Create JSON – The Each day WTF

Faheem

At present’s nameless submission is a delightfully easy line of JavaScript that’s really the archetype of a consultant line.

$json = "{";

Now, I do know you are pondering, “I see a ‘$’ sigil, it have to be PHP or possibly Perl!” No, it is JavaScript. And as you collect from the code, that is the primary line of an extended block that constructs JSON by way of string concatenation.

And sure, JavaScript has built-in features for this, which do higher than that. Whereas it’s doable That they should create customized JSON to help a parser that misbehaves on the opposite aspect is WTF in its personal proper – and that is not the case right here. Accountable builders merely did not know the way to deal with JSON in JavaScript.

Have you learnt what else they did not perceive? Supply management and help instruments, so all JavaScript recordsdata have been named e.g david.js And lisa.js– Every developer obtained their very own JS file to work with, so that they did not battle with anybody else.

Leave a Comment