Comment On JavaScript JSON Parsing

No data interchange format is perfect. ASN.1 (Abstract Syntax Notation One) is probably the closest (it's by far the most flexible and comprehensive), but since no one's really heard of it, it may as well be Esperanto. Although XML has become the de-facto standard, JSON (JavaScript Object Notation) has been gaining favor – especially for simple operations on the web. [expand full text]
« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Re: JavaScript JSON Parsing

2011-12-22 09:02 • by Martijn Otto (unregistered)
The biggest WTF is of course that a space was added after the {. This means the JSON was created manually, instead of using one of the myriad available functions to do exactly that.

Re: JavaScript JSON Parsing

2011-12-22 09:06 • by Nag-Geoff (unregistered)
By all natural laws of computing, a weakly typed language like javascript should have been extinct the minute it came out of the door.

Re: JavaScript JSON Parsing

2011-12-22 09:10 • by Lolozaurus (unregistered)
370422 in reply to 370421
Nag-Geoff:
By all natural laws of computing, a weakly typed language like javascript should have been extinct the minute it came out of the door.


Yeah, because in other languages you can't manually parse a (non)standard response string. And this is what strong/weak types are all about, isn't, mr Logic ?

Re: JavaScript JSON Parsing

2011-12-22 09:13 • by Hercules (unregistered)
This code smells worse that a Lemnian Woman.

Re: JavaScript JSON Parsing

2011-12-22 09:17 • by Dennis (unregistered)
Yeah, because using eval() is widely recommended... *cough*

Re: JavaScript JSON Parsing

2011-12-22 09:18 • by Matt Westwood
The real WTF is that it's the shortest day of the year, north of the 50th parallel, right in the middle of winter, and I'm sitting here with the window wide open, sweating like a Pee Eye Jee ...

Re: JavaScript JSON Parsing

2011-12-22 09:26 • by Thomas (unregistered)
TRWTF is using "/{2}" in a RegExp to find "//".

W{1}T{1}F{1}

Re: JavaScript JSON Parsing

2011-12-22 09:26 • by Kh3pra (unregistered)
370427 in reply to 370425
Matt Westwood:
The real WTF is that it's the shortest day of the year, north of the 50th parallel, right in the middle of winter, and I'm sitting here with the window wide open, sweating like a Pee Eye Jee ...



why?

Re: JavaScript JSON Parsing

2011-12-22 09:28 • by snoofle
I pity the poor, maligned space character. It is generally treated as insignificant in a world of otherwise significant characters.

I salute you, little friend!

Re: JavaScript JSON Parsing

2011-12-22 09:32 • by Qŭert (unregistered)
Yay, Esperanto mentioned on thedailywtf!

As JoMo says, "Lernu Esperanton nun!"

Captcha: valetudo (everything goes)

Re: JavaScript JSON Parsing

2011-12-22 09:34 • by vt_mruhlin (unregistered)
370431 in reply to 370420
Martijn Otto:
The biggest WTF is of course that a space was added after the {. This means the JSON was created manually, instead of using one of the myriad available functions to do exactly that.


I'm not sure you can jump to that conclusion. Suppose you want to dump the JSON string into a log file in a readable format before responding. You'd want to encode the original JSON blob in pretty format, with newlines and indentation. But when it comes time to go over the wire, you want to minify it, and maybe your minifier isn't perfect.

Re: JavaScript JSON Parsing

2011-12-22 09:34 • by Anonymoose (unregistered)
370432 in reply to 370424
In JSON parsing, it's okay, however almost all modern browsers (Chrome 7?+ Safari 5+ FF 4+ Opera 10.50+ IE9+) all expose a global JSON object that has "stringify" and "parse" methods.

You're supposed to do a couple of quick/dirty regex's to verify integrity but those are for old browsers only. It's okay to use eval in this context or to just use the function constructor with return (i.e. (new Function("return "+JSONDATA)() )

Re: JavaScript JSON Parsing

2011-12-22 09:35 • by PedanticCurmudgeon
370433 in reply to 370425
Matt Westwood:
The real WTF is that it's the shortest day of the year, north of the 50th parallel, right in the middle of winter, and I'm sitting here with the window wide open, sweating like a Pee Eye Jee ...
TRWTF is that you're posting here on your day off.

Re: JavaScript JSON Parsing

2011-12-22 09:46 • by Code Slave
370434 in reply to 370425
Matt Westwood:
The real WTF is that it's the shortest day of the year, north of the 50th parallel, right in the middle of winter, and I'm sitting here with the window wide open, sweating like a Pee Eye Jee ...

(actually, it's the 1st day of Winter)

Be grateful... you could be North of the 50th parallel on the vernal equinox (1st day of spring), with the window frozen shut and afraid that if you go out side an important part of your body might freeze and snap off.

Re: JavaScript JSON Parsing

2011-12-22 09:50 • by DES
TRWTF is the claim that “no one's really heard of ASN.1”

Re: JavaScript JSON Parsing

2011-12-22 09:51 • by Thomas (unregistered)
370436 in reply to 370420
Martijn Otto:
The biggest WTF is of course that a space was added after the {. This means the JSON was created manually, instead of using one of the myriad available functions to do exactly that.


No, it might as well mean that they decided to use a different library, the lib was updated, or a config parameter was changed.

Re: JavaScript JSON Parsing

2011-12-22 09:56 • by Pim
The real WTF is no "Frist". What's with you guys?

Re: JavaScript JSON Parsing

2011-12-22 09:59 • by Leo (unregistered)
Come on people: the real WTF is Javascript.

Re: JavaScript JSON Parsing

2011-12-22 10:01 • by TRWTF (unregistered)
TRWTF is of course:

"No data interchange format is perfect. ASN.1 (Abstract Syntax Notation One) is probably the closest (it's by far the most flexible and comprehensive)"

ASN.1 close to perfect?

Re: JavaScript JSON Parsing

2011-12-22 10:05 • by Gervase Markham (unregistered)
TRWTF is the idea that ASN.1 is the perfect data interchange format. Firstly, it's binary, and being textual is important. But secondly, ASN.1 parsers have a history of nasty buffer overflows. Perhaps this was partly down to the implementation languages, but it doesn't suggest that it's an easy-to-parse format...

Re: JavaScript JSON Parsing

2011-12-22 10:07 • by DES
370441 in reply to 370434
Code Slave:
Be grateful... you could be North of the 50th parallel on the vernal equinox (1st day of spring), with the window frozen shut and afraid that if you go out side an important part of your body might freeze and snap off.


I live smack dab on the 60th, and neither the winter solstice nor the vernal equinox bother me much.

Re: JavaScript JSON Parsing

2011-12-22 10:10 • by imgx64 (unregistered)
TRWTF is praising ASN.1. ASN.1 is the most needlessly convoluted "standard" data exchange format ever created.

You know how the SQL "standard" is so big that there are absolutely zero fully conforming implementations? ASN.1 is the same thing. Besides its complexity, it also dictates worthless small details but leaves big issues unresolved.

The only possible way someone could implement ASN.1 without losing his sanity is implementing only enough to interact with whatever legacy system that uses it then stop immediately when it starts to "barely work" (that's the best you can achieve with ASN.1 anyway).

Re: JavaScript JSON Parsing

2011-12-22 10:11 • by Beowulff (unregistered)
It depends if this really is a WTF, or simply a small bug in a regex. If this were the only line of JSON that my entire application would ever encounter, I'd might be tempted to avoid adding a dependency to a JSON parser and just use a regex to parse it as well. If the application has to deal with JSON all over the place, however, use a JSON library instead.

Re: JavaScript JSON Parsing

2011-12-22 10:15 • by MojoMonkeyfish (unregistered)
"JSON (JavaScript Object Notation) has been gaining favor"

That's the understatement of the day. From my experience, at least.

XML has a huge overhead, on documents large and small, and is less readable than JSON (not that human readability was actually a design consideration).

Also, "TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again? I mean, it's not my field. I work on server-side, and I don't particularly like Java, but it's hardly a WTF to work with it, especially in this context.

Re: JavaScript JSON Parsing

2011-12-22 10:18 • by No one (unregistered)
370445 in reply to 370435

I haven't heard of it... not really

Re: JavaScript JSON Parsing

2011-12-22 10:19 • by Hatshepsut
370446 in reply to 370440
Gervase Markham:
TRWTF is the idea that ASN.1 is the perfect data interchange format. Firstly, it's binary...


Doesn't that depend on the encoding rules used?

Re: JavaScript JSON Parsing

2011-12-22 10:19 • by No one (unregistered)
370447 in reply to 370435
DES:
TRWTF is the claim that “no one's really heard of ASN.1”


I haven't heard of it... not really.

Re: JavaScript JSON Parsing

2011-12-22 10:19 • by imgx64 (unregistered)
370448 in reply to 370444
MojoMonkeyfish:
Also, "TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again? I mean, it's not my field. I work on server-side, and I don't particularly like Java, but it's hardly a WTF to work with it, especially in this context.


CoffeeScript? Dash? Java/GWT?

Sure, they all compile to JavaScript behind the scenes, but by that reasoning, all programming languages are the same as assembly.

Re: JavaScript JSON Parsing

2011-12-22 10:24 • by Don (unregistered)
370449 in reply to 370425
Matt Westwood:
The real WTF is that it's the shortest day of the year, north of the 50th parallel, right in the middle of winter, and I'm sitting here with the window wide open, sweating like a Pee Eye Jee ...

TRWTF is spelling out the letter "G" using a "J".

Re: JavaScript JSON Parsing

2011-12-22 10:39 • by Nag-Geoff (unregistered)
370450 in reply to 370425
Yeah, curry does that to me too!

Re: JavaScript JSON Parsing

2011-12-22 10:46 • by pjt33
370451 in reply to 370444
MojoMonkeyfish:
Also, "TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again? I mean, it's not my field. I work on server-side, and I don't particularly like Java, but it's hardly a WTF to work with it, especially in this context.

Anyone want to open a book on how many people will explain the difference between JS and Java?

Re: JavaScript JSON Parsing

2011-12-22 10:51 • by lesle (unregistered)
370452 in reply to 370441
DES:
Code Slave:
Be grateful... you could be North of the 50th parallel on the vernal equinox (1st day of spring), with the window frozen shut and afraid that if you go out side an important part of your body might freeze and snap off.


I live smack dab on the 60th, and neither the winter solstice nor the vernal equinox bother me much.


Cross Quarter, Solstice and Equinox dates & times
(cearth's position relative to seasonal cusps)

http://www.archaeoastronomy.com/myclock.shtml

Re: JavaScript JSON Parsing

2011-12-22 10:53 • by Jerry (unregistered)
370453 in reply to 370427
Kh3pra:
Matt Westwood:
The real WTF is that it's the shortest day of the year, north of the 50th parallel, right in the middle of winter, and I'm sitting here with the window wide open, sweating like a Pee Eye Jee ...
why?
He thought he saw a female.

Re: JavaScript JSON Parsing

2011-12-22 10:53 • by Dogbrags (unregistered)
370454 in reply to 370428
snoofle:
I pity the poor, maligned space character. It is generally treated as insignificant in a world of otherwise significant characters.

I salute you, little friend!


DO a google search for the whitespace language. In whitespace, a space character is a first-class citizen.

Re: JavaScript JSON Parsing

2011-12-22 10:57 • by Ralph (unregistered)
370455 in reply to 370444
MojoMonkeyfish:
"TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again?
High speed automatic weaponry, aimed at anyone who thinks they deserve to take control of my computer.

Re: JavaScript JSON Parsing

2011-12-22 11:00 • by Zylon
370456 in reply to 370455
Ralph:
MojoMonkeyfish:
"TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again?
High speed automatic weaponry, aimed at anyone who thinks they deserve to take control of my computer.

Not sure if trolling or stupid.

If not trolling, then I'll assume by your statement that you don't run ANY software not written by anyone other than yourself.

Re: JavaScript JSON Parsing

2011-12-22 11:06 • by Greased Up Monkey (unregistered)
370457 in reply to 370455
Ralph:
MojoMonkeyfish:
"TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again?
High speed automatic weaponry, aimed at anyone who thinks they deserve to take control of my computer.

Chrome has Extensions.

Mozilla Firefox has the Greasemonkey Plug-In

Both allow you to write Javascript that will be run on pages you specify. Between this an No Script, you can assert 100% control over every bit of client side browser scripting that runs on your computer.

And you don't even need to reload.

Re: JavaScript JSON Parsing

2011-12-22 11:11 • by Kivi
370458 in reply to 370434
Code Slave:
(actually, it's the 1st day of Winter)

The solstice is midwinter. Winter's only one day long where you live?

Re: JavaScript JSON Parsing

2011-12-22 11:12 • by Jim Rees (unregistered)
Others have said this, but it bears repeating. The part of this that had me smacking my head in disbelief is the claim that ASN.1 is anywere near perfect.

Re: JavaScript JSON Parsing

2011-12-22 11:29 • by TrailerParkJihad
370460 in reply to 370457
Greased Up Monkey:
Ralph:
MojoMonkeyfish:
"TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again?
High speed automatic weaponry, aimed at anyone who thinks they deserve to take control of my computer.

Chrome has Extensions.

Mozilla Firefox has the Greasemonkey Plug-In

Both allow you to write Javascript that will be run on pages you specify. Between this an No Script, you can assert 100% control over every bit of client side browser scripting that runs on your computer.

And you don't even need to reload.

^ and my water came out of my face-breathing holes, you owe me a dry shirt.

Re: JavaScript JSON Parsing

2011-12-22 11:32 • by Kempeth (unregistered)
The real "The real WTF" is the redirect url: "http://initrode-global.com/auth/login.do?cmd=auth-success"

What does it matter if the javascript breaks some day? You can just type in that url yourself.

Re: JavaScript JSON Parsing

2011-12-22 11:36 • by Bobby Tables (unregistered)
370462 in reply to 370458
Kivi:
Code Slave:
(actually, it's the 1st day of Winter)

The solstice is midwinter. Winter's only one day long where you live?

Not sure if troll, or just stupid. But the winter solstice is the 1st day of winter.

http://en.wikipedia.org/wiki/Winter_solstice

Re: JavaScript JSON Parsing

2011-12-22 11:36 • by Ralph (unregistered)
370463 in reply to 370456
Zylon:
Ralph:
MojoMonkeyfish:
"TRWTF is Javascript?" What language were you planning on using for your client side browser scripting again?
High speed automatic weaponry, aimed at anyone who thinks they deserve to take control of my computer.

Not sure if trolling or stupid.

If not trolling, then I'll assume by your statement that you don't run ANY software not written by anyone other than yourself.
So you're asserting that software written by professional developers employed by reputable vendors, or peer-reviewed by established distribution mechanisms, installed and configured by an administrator after ensuring current backups, has the same threat model as software automatically loaded and run in real time, written by amateur anonymous random asshats half a world away?

Now let's discuss who's stupid, since you seem to consider that a productive way to frame a debate.

Re: JavaScript JSON Parsing

2011-12-22 11:36 • by Zylon
370464 in reply to 370461
Kempeth:
The real "The real WTF" is the redirect url: "http://initrode-global.com/auth/login.do?cmd=auth-success"

What does it matter if the javascript breaks some day? You can just type in that url yourself.

That WHOOOSH sound... can you hear it?

Re: JavaScript JSON Parsing

2011-12-22 11:38 • by Ricky (unregistered)
370465 in reply to 370464
Zylon:
Kempeth:
The real "The real WTF" is the redirect url: "http://initrode-global.com/auth/login.do?cmd=auth-success"

What does it matter if the javascript breaks some day? You can just type in that url yourself.

That WHOOOSH sound... can you hear it?
No, no! What is it? A jet? Superman?

Re: JavaScript JSON Parsing

2011-12-22 11:40 • by Zylon
370466 in reply to 370463
Ralph:
So you're asserting that software written by professional developers employed by reputable vendors, or peer-reviewed by established distribution mechanisms, installed and configured by an administrator after ensuring current backups, has the same threat model as software automatically loaded and run in real time, written by amateur anonymous random asshats half a world away?

Now let's discuss who's stupid, since you seem to consider that a productive way to frame a debate.

You are, if you believe that all locally installed software falls in the "reputable" category, and that all web software falls in the "amateur" category.

You also seem to be assuming a corporate IT environment, for some gonzo reason.

Re: JavaScript JSON Parsing

2011-12-22 11:42 • by TrailerParkJihad
370467 in reply to 370466
Zylon:
Ralph:
So you're asserting that software written by professional developers employed by reputable vendors, or peer-reviewed by established distribution mechanisms, installed and configured by an administrator after ensuring current backups, has the same threat model as software automatically loaded and run in real time, written by amateur anonymous random asshats half a world away?

Now let's discuss who's stupid, since you seem to consider that a productive way to frame a debate.

You are, if you believe that all locally installed software falls in the "reputable" category, and that all web software falls in the "amateur" category.

You also seem to be assuming a corporate IT environment, for some gonzo reason.


Except he didn't say "all locally installed software is reputable" or that "all web software is amateur", those are conclusions you extrapolated on your own, and are in no way even alluded to in what he said. So no, it's still you.

Re: JavaScript JSON Parsing

2011-12-22 11:46 • by Kempeth (unregistered)
370468 in reply to 370464
Zylon:
Kempeth:
The real "The real WTF" is the redirect url: "http://initrode-global.com/auth/login.do?cmd=auth-success"

What does it matter if the javascript breaks some day? You can just type in that url yourself.

That WHOOOSH sound... can you hear it?
Nope. Can you?

Re: JavaScript JSON Parsing

2011-12-22 11:50 • by TheCPUWizard
370469 in reply to 370435
DES:
TRWTF is the claim that “no one's really heard of ASN.1”


You have heard of ASN.1..... therefore you are really no one!

<grin>

[A healyth and happy holiday season to all!]

Re: JavaScript JSON Parsing

2011-12-22 11:50 • by Please - no more variables/functions names foo and bar (unregistered)
To quote a book by O'Reilly or regular expressions...

A programmer is trying to solve a problem. She says, "I know, I will use regular expressions.". Now she has two problems.

« PrevPage 1 | Page 2 | Page 3 | Page 4 | Page 5Next »

Add Comment