• 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.

  • 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.

  • Lolozaurus (unregistered) in reply to Nag-Geoff
    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 ?

  • Hercules (unregistered)

    This code smells worse that a Lemnian Woman.

  • Dennis (unregistered)

    Yeah, because using eval() is widely recommended... cough

  • (cs)

    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 ...

  • Thomas (unregistered)

    TRWTF is using "/{2}" in a RegExp to find "//".

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

  • Kh3pra (unregistered) in reply to Matt Westwood
    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?

  • (cs)

    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!

  • Qŭert (unregistered)

    Yay, Esperanto mentioned on thedailywtf!

    As JoMo says, "Lernu Esperanton nun!"

    Captcha: valetudo (everything goes)

  • vt_mruhlin (unregistered) in reply to Martijn Otto
    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.

  • Anonymoose (unregistered) in reply to Dennis

    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)() )

  • (cs) in reply to Matt Westwood
    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.
  • (cs) in reply to Matt Westwood
    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.

  • (cs)

    TRWTF is the claim that “no one's really heard of ASN.1”

  • Thomas (unregistered) in reply to Martijn Otto
    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.

  • (cs)

    The real WTF is no "Frist". What's with you guys?

  • Leo (unregistered)

    Come on people: the real WTF is Javascript.

  • 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?

  • 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...

  • (cs) in reply to Code Slave
    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.

  • 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).

  • 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.

  • 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.

  • No one (unregistered) in reply to DES

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

  • (cs) in reply to Gervase Markham
    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?

  • No one (unregistered) in reply to DES
    DES:
    TRWTF is the claim that “no one's really heard of ASN.1”

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

  • imgx64 (unregistered) in reply to MojoMonkeyfish
    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.

  • Don (unregistered) in reply to Matt Westwood
    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".
  • Nag-Geoff (unregistered) in reply to Matt Westwood

    Yeah, curry does that to me too!

  • (cs) in reply to MojoMonkeyfish
    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?
  • lesle (unregistered) in reply to DES
    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

  • Jerry (unregistered) in reply to Kh3pra
    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.
  • Dogbrags (unregistered) in reply to snoofle
    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.

  • Ralph (unregistered) in reply to MojoMonkeyfish
    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.
  • (cs) in reply to Ralph
    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.

  • Greased Up Monkey (unregistered) in reply to Ralph
    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.

  • (cs) in reply to Code Slave
    Code Slave:
    (actually, it's the 1st day of Winter)
    The solstice is midwinter. Winter's only one day long where you live?
  • 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.

  • (cs) in reply to Greased Up Monkey
    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.
  • 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.

  • Bobby Tables (unregistered) in reply to Kivi
    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

  • Ralph (unregistered) in reply to Zylon
    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.

  • (cs) in reply to Kempeth
    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?

  • Ricky (unregistered) in reply to Zylon
    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?

  • (cs) in reply to Ralph
    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.

  • (cs) in reply to Zylon
    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.

  • Kempeth (unregistered) in reply to Zylon
    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?

  • (cs) in reply to DES
    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!]

  • 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.

Leave a comment on “JavaScript JSON Parsing”

Log In or post as a guest

Replying to comment #:

« Return to Article