Live data from Hacker News

Why is JSON so popular? Developers want out of the syntax business

blog.mongolab.com

31–40 of 133 posts

Re: Why is JSON so popular? Developers want out of the syntax business

#31

The baby that has been thrown out with the bathwater here is a schema/data description layer. NOT , I repeat NOT , I repeat NOT for verification but rather for tools, so that people working in strongly typed languages can interact with JSON services in a reasonable manner. Unfortunately the one option I see, JSON Schema, appears to have caught the XML/Java bug, and has gotten very complicated.

Use protocol buffers! As easy to use as JSON in dynamic languages, gives you strongly-typed accessors in static languages.

Re: Why is JSON so popular? Developers want out of the syntax business

#32

The best way I've encountered to construct XML: first-name John last-name Smith I kid you not. That's what I'm dealing with at work right now. Thank you, enterprise SOAP solutions.

xmlrpc[1] is similar.

    
    
       examples.getStateName
       
          
             41
          
       
    
my favorite part[2] is how only contain elements within. each has exactly one child. Why is it not just 41?. Its no surprise that the creator of xmlrpc was involved with soap.

[1] http://www.xmlrpc.com/spec [2] not really.

Re: Why is JSON so popular? Developers want out of the syntax business

#33

The best way I've encountered to construct XML: first-name John last-name Smith I kid you not. That's what I'm dealing with at work right now. Thank you, enterprise SOAP solutions.

I've worked with worse:

  
    
      
        John
        Smith
      
      
        123 Some Street
        Blah
        Blah
        Blah
      
... and so on. I can't think of any advantage to (or excuse for) doing it this way. The only possible reason for it that I can think of, is rather comprehensive ignorance of how XML and related standards work.

Re: Why is JSON so popular? Developers want out of the syntax business

#34

The mostly-just-one-way-to-organize-it approach cannot be overstated here. XPath is neat, but iterating through parser results is still a pain.

That because XML does not map well to Simula style OO. "Iterating" XML in XSLT (a language designed to manipulate XML) is way less of a pain.

I don't disagree with this, but I think there's something wrong when need another markup language to deal with the first markup language.

Re: Why is JSON so popular? Developers want out of the syntax business

#35
post #4

The post actually appears to endorse using eval to parse JSON. Not only does that allow invalid JSON through, it disallows some valid JSON, and of course is a huge security hole. If you want to handle JSON data in JavaScript use JSON.parse -- it's the safest, fastest, and most correct path to having your data available to you. [update: edited to remove bizarre use of whole vs hole... boggles ]

Yes! I was shocked to see him recommend the use of a straight eval for parsing JSON. json2.js is a must! JSON.parse and JSON.stringify are your friends. https://github.com/douglascrockford/JSON-js/blob/master/json...

Keep in mind that json2.js' JSON.parse() ultimately uses eval() after a few sanity checks. Definitely better than a blind eval(), but not quite the panacea it's often purported to be.

Re: Why is JSON so popular? Developers want out of the syntax business

#37

The baby that has been thrown out with the bathwater here is a schema/data description layer. NOT , I repeat NOT , I repeat NOT for verification but rather for tools, so that people working in strongly typed languages can interact with JSON services in a reasonable manner. Unfortunately the one option I see, JSON Schema, appears to have caught the XML/Java bug, and has gotten very complicated.

I couldn't agree more!

Out of frustration with existing schema languages and tool support for them, I've been working on Piqi[1] which is concise, expressive and agnostic to data representation formats. It works for JSON, XML and Protocol Buffers.

[1] http://piqi.org

Re: Why is JSON so popular? Developers want out of the syntax business

#38

Earlier quoted context omitted.

what else do you do with a data structure besides walk it at some point? JSON comes out as an acyclic object graph in javascript, so what it still needs to be walked to actually do something with the data. The difference between walking JSON and XML is simply the syntax of the parser library your are using. The problem with XML is it has things that don't map directly to most OO languages, like node order matters, an…

Reiterating the point the blog post makes, but: It's very very easy to structure the same data in different ways in XML. While JSON has the same issue, it's a lot harder to do and you have less flexibility in making bad storage decisions. You are absolutely right on walking the structure. JSON just tends to be easier (in my experience), even when working with XML libraries that make it less of a pain.

I'll give the opposing opinion that I find working with XML easier than JSON, but mostly because of QueryPath.

Re: Why is JSON so popular? Developers want out of the syntax business

#39
post #7

Ironically, php provides a way to access XML data almost as easily as JASON data - SimpleXML. Do other languages/frameworks really have nothing similar?

While SimpleXML gives you an easy way to walk the tree, it still requires you to actually do it. All 3 of those examples would require slightly different calls to SimpleXML to handle.

The moment I realized I could do json_decode(json_encode($simple_xml_object),true); to turn a complex SimpleXML object into an array was the happiest moment of my life.

Re: Why is JSON so popular? Developers want out of the syntax business

#40
post #4

The post actually appears to endorse using eval to parse JSON. Not only does that allow invalid JSON through, it disallows some valid JSON, and of course is a huge security hole. If you want to handle JSON data in JavaScript use JSON.parse -- it's the safest, fastest, and most correct path to having your data available to you. [update: edited to remove bizarre use of whole vs hole... boggles ]

I gotta ask: that just sounds wrong to me. The fact that it used a built-in parser was supposed to have been a feature of JSON. Have we pedantricized that into a bad thing now too? What's the disadvantage of "allowing invalid JSON" in an application protocol you control? Likewise, what's the value of valid JSON (I honestly don't know what the example here is) that can't be parsed by a Javascript interpreter?

And where does the "huge security hole" come from? I certainly hope you're not saying that you trust requests generated by client code...

Post reply on HN