Live data from Hacker News

JSON or XML: Just Decide

mnot.net

21–30 of 44 posts

Re: JSON or XML: Just Decide

#21
post #16

I like Turtle: dc:title "RDF/XML Syntax Specification (Revised)" ; ex:editor [ ex:fullname "Dave Beckett"; ex:homePage ] . It's only useful if you drank the RDF kool-aid (like I have), though.

You have good taste, since I invented Turtle. To keep this on topic, I've been using JSON for data web APIs since that's what it's best at. It sucks at: markup and graphs of course.

We use JSON for graphs. What sucks about it? In what sense is XML better at representing graphs?

Re: JSON or XML: Just Decide

#22
post #14

Or... they're designed for different purposes and not even competitors. XML is a markup language: http://en.wikipedia.org/wiki/Markup_language It was designed for documents. Try converting an HTML page to JSON. Try something as simple as: Hello World! The most common introductory program is called Hello, World . Go on. If you think JSON wins, just do it, and post it below. The problem was when people started mis-appl…

Yes, JSON is no ML, but YAML is, which is a superset of JSON's semantics/features. You're perfectly right that JSON is not always the right tool for transporting a document, but I still wouldn't regard XML as the best tool for any of those cases.

Re: JSON or XML: Just Decide

#23
This "article" is odd. I've worked with multiple systems and I don't see a reason why one data model can't be bound to XML and JSON without being awkward. It's so incredibly EASY to output and input with both, why not? Personally I prefer JSON as I haven't found anything that can't be represented within it.

I didn't see any example within the article regarding JSON formats that generate awkard XML ad vice versa. Does anyone have examples of that?

Re: JSON or XML: Just Decide

#24

JSON is great, but it is not nearly as flexible as XML, partly because of attributes. Also, because of it's JS heritage and compatibility, lots of common things are not representable in JSON. This is mostly because object keys MUST be strings. Examples: In [1]: from simplejson import dumps In [2]: dumps({1: 5, '1': 0}) Out[2]: '{"1": 0, "1": 5}' Derp, good luck figuring out what that is supposed to mean. In [3]: dump…

I don't really understand your point here. Those JSON data dumps don't make any sense...and wouldn't make sense as XML either. Why wouldn't you enforce a schema? I've never worked on a system that didn't do validation and schema enforcement regardless of xsd, json, etc; you need to have well defined ways of laying out your data or it's going to be useless regardless of the format used.

>JSON is great, but it is not nearly as flexible as XML, partly because of attributes.

Attributes can be stored in JSON as well. XML and JSON simply store data in different ways.

>Also, because of it's JS heritage and compatibility, lots of common things are not representable in JSON.

Like what? You can actually put real values in their correct types with JSON. You can't do that with XML, so what types of items are not representable?

>This is mostly because object keys MUST be strings.

The same is true for XML so I'm not sure what your point is. Don't nodes and attribute names need to be strings in XML?

Re: JSON or XML: Just Decide

#25

Use the right tool for the job. I wouldn't say that XML or JSON is always right. But I will say that I believe XML has a better ecosystem around it; with things like XSD, XSLT, XQuery/XPath, etc., and some pretty easy to use data-binding frameworks like JAX-B. My feeling is that XML makes it a lot easier to do certain classes of things that I want to do, like taking a business event message off a queue, match it agai…

There are things that seem "natural" when using XML? News to me :)

Re: JSON or XML: Just Decide

#26
post #21
post #16

Earlier quoted context omitted.

You have good taste, since I invented Turtle. To keep this on topic, I've been using JSON for data web APIs since that's what it's best at. It sucks at: markup and graphs of course.

We use JSON for graphs. What sucks about it? In what sense is XML better at representing graphs?

There's no way to point from one part of a JSON doc to another without inventing a terminology or convention for marking the start (anchor) and end of the arc (href). People use 'id' for one end but there's no way to say a json value is actually a reference (href) not just a string. XML has that built in (ID IDREF) and so does HTML, but I didn't say XML was better, I said JSON sucks at markup and graphs. JSON's handy for serializing trees of data with no loops.

Re: JSON or XML: Just Decide

#27

Use the right tool for the job. I wouldn't say that XML or JSON is always right. But I will say that I believe XML has a better ecosystem around it; with things like XSD, XSLT, XQuery/XPath, etc., and some pretty easy to use data-binding frameworks like JAX-B. My feeling is that XML makes it a lot easier to do certain classes of things that I want to do, like taking a business event message off a queue, match it agai…

Yeah, the XML ecosystem is priceless. XPath, for example, is the one reason a project I'm working on can't switch to JSON.

Re: JSON or XML: Just Decide

#28
post #14

Or... they're designed for different purposes and not even competitors. XML is a markup language: http://en.wikipedia.org/wiki/Markup_language It was designed for documents. Try converting an HTML page to JSON. Try something as simple as: Hello World! The most common introductory program is called Hello, World . Go on. If you think JSON wins, just do it, and post it below. The problem was when people started mis-appl…

Well here's my attempt: http://hpaste.org/66897

Re: JSON or XML: Just Decide

#30
post #8

Earlier quoted context omitted.

You're feigning outrage. It's a valid and well-documented design decision that keys in JSON are strings. If you want a language-specific serialization format based on JSON, come up with a dialect.

Being 'well documented' doesn't make it less of a pain.

But I mean, yes it does. Imagine if implementations were inconsistent as to what they allowed for JSON keys so that your browser couldn't understand the JSON your python code sent it. That scenario is prevented by the limitation being well documented.
Post reply on HN