Article 6TCT4 Representative Line: Generate JSON

Representative Line: Generate JSON

by
Remy Porter
from The Daily WTF on (#6TCT4)
Story Image

Today's anonymous submission is a delightfully simple line of JavaScript which really is an archetype of a representative line.

$json = "{";

Now, I know you're thinking, "I see a '$' sigil, this must be PHP or maybe Perl!" No, this is JavaScript. And as you might be gathering from the code, this is the first line in a long block that constructs JSON through string concatenation.

And yes, JavaScript has built in functions for this, which work better than this. While it's possible that they need to generate custom JSON to support a misbehaving parser on the other side, that's it's own WTF- and it isn't the case here. The developers responsible simply didn't know how to handle JSON in JavaScript.

Do you know what else they couldn't understand? Source control and collaboration tools, so all of the JavaScript files were named things like david.js and lisa.js- each developer got their own JS file to work on, so they didn't conflict with anyone else.

[Advertisement] Picking up NuGet is easy. Getting good at it takes time. Download our guide to learn the best practice of NuGet for the Enterprise.
External Content
Source RSS or Atom Feed
Feed Location http://syndication.thedailywtf.com/TheDailyWtf
Feed Title The Daily WTF
Feed Link http://thedailywtf.com/
Reply 0 comments