Re: New to JSON




"Tom Cole" <tcole6@xxxxxxxxx> wrote in message
news:1155823853.756624.48550@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Thanks for the tip. What I'm working on (in addition to learning JSON)
is writing an XML to JSON converter. This can be used as a middle tier
to some web services we already have. This way they can still service
existing setups, and provide JSON to newer applications.

This was a snippet of an auto-generated output from this converter. The
XML it came from was:

<headers>
<date>16 Aug 2006 19:53:03 GMT</date>
<header>
<name>accept</name>
<value>*/*</name>
</header>
<header>
<name>accept-language</name>
<value>en-us</value>
</header>
.....
</headers>

So given that, do you have a recommendation that is generic enough to
give a JSON output like what you recommend, but still work with nearly
any XML file?


The problem is that both raw XML and JSON are typeless. A 'generic'
conversion of XML to JSON is simply a non-starter the resulting JSON is
really ugly to use.

Now if you have specific XML schemas that you want to transform to JSON then
you are in with a chance creating an XSL for each.

What benefits do you perceive JSON has over just sticking with XML?

Next I get to figure out how to handle attributes...

Tom Cole wrote:
I'm new to JSON but see how it can be an improvement over XML for some
things.

I've modified a test servlet to return the following string with a
content type of text/x-json:

{ header: { date: "16 Aug 2006 19:53:03 GMT", headers: [ { name:
"accept", value: "*/*" }, { name: "accept-language", value: "en-us" },
{ name: "referer", value: "http://njep11/Ajax/"; }, { name:
"content-type", value: "application/x-www-form-urlencoded" }, { name:
"accept-encoding", value: "gzip, deflate" }, { name: "user-agent",
value: "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR
1.0.3705; .NET CLR 1.1.4322)" }, { name: "host", value: "njep11" }, {
name: "content-length", value: "9" }, { name: "connection", value:
"Keep-Alive" }, { name: "cache-control", value: "no-cache" }] } }

On the client side I receive this an create an object via eval:

var object = eval('(' + xmlhttp.respongeText + ')');

If I do an alert(object.toString()) I get [Object object]. So I thought
it was working okay. However if I try to access object.headers[0].name
I get an error stating "headers.0 is null or not an object.

Is my JSON string correct? I'm not sure what role (if any) whitespace
plays in this type. I'm expecting it to create a object of type header
with a variable date and an array of objects that contain name and
value variables.

Thanks in advance.



.



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)
  • Re: New to JSON
    ... What I'm working on (in addition to learning JSON) ... is writing an XML to JSON converter. ...
    (microsoft.public.scripting.jscript)
  • Re: XML<-> JSON conversion. What do you think?
    ... then most of implementations of conversion from XML to JSON are naïve! ...
    (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)