Re: XML<-> JSON conversion. What do you think?



Lasse Reichstein Nielsen ha scritto:
Not really. It shows that a particularly naïve implementation
of a conversion from XML to JSON doesn't work well.

Really, then most of implementations of conversion from XML to JSON are naïve!

What if the conversion of <e>
some
<a>textual</a>
content
</e>

was:
{"tag": "e",
"content" : [ "some", {"tag": "a", "content": ["textual"]}
"content" ]}

What is the big difference then?

For JSON, "textual" is a value of "a" and then { a: "textual" }.
This convertion is your expansive implementation created to bypass the JSON limitations...
In fact, to obtain the string "some" instead of (example) e["#text"], you must use a blinded mode tag.content[1], while it is more correct to log on with the real name of the object/tag, that is "e"!

I think
to use JSON to transmit simples data and XML for structured data.

Your choice. Neither is inherently better (although JSON is often
shorter), but their performances depend on the choice of encoding
as much as the format of the data.

XML only has raw text and elements nodes. Element nodes both work as a
list of XML nodes and as a map from strings to strings (attributes),
and it has a type itself (the tag name). Everything is rolled into
this one compound construct.

JSON has two types of compound structures: (unordered) Maps and
(ordered) Lists (i.e., indexed by either name or by number).

In that sense, JSON is richer than XML, where name-indexed attributes can only contain simple text.

I find that most data can be well represented in JSON, but starting
with XML data obviously makes JSON look worse than XML. Just as starting
with JSON data would probably make XML look worse.

/L


Can you suggests to me a good XML-JSON converter?
.



Relevant Pages

  • Re: XML<-> JSON conversion. What do you think?
    ... JSON limitations... ... JSON is not XML. ... Converting one to the other literally will ... var attrs = node.attributes; ...
    (comp.lang.javascript)
  • XML<-> JSON conversion. What do you think?
    ... According to Stefan Goessner, to obtain a correct conversion from XML to JSON it must apply some patterns to maintain order and structure of the elements. ...
    (comp.lang.javascript)
  • Re: More bollocks from biggots
    ... The paper don't say that the best workaround is to use a XML ... A server can mount a defense against JavaScript Hijacking by responding ... on adding support for JSON in future versions. ...
    (comp.os.vms)
  • Re: XML<-> JSON conversion. What do you think?
    ... of a conversion from XML to JSON doesn't work well. ... to use JSON to transmit simples data and XML for structured data. ... XML only has raw text and elements nodes. ...
    (comp.lang.javascript)
  • Re: New to JSON
    ... is writing an XML to JSON converter. ... and provide JSON to newer applications. ... This was a snippet of an auto-generated output from this converter. ...
    (microsoft.public.scripting.jscript)