>
> JavaScript generally drops the quotes:
var foo = {bar:100};
Sure, that's because in that example, with regards to the key, that's a
valid string and JavaScript knows you're talking about a an object property.
With regards to the value, that's because JavaScript is doing dynamic
typing (it is a number).
This is the correct behavior. JSON paths can be represented in one of two
> ways:
>
a.b.c
> ["a"]["b"]["c"]
>
> or a combination thereof
>
> a["b"].c
I disagree - a key with period in it is valid as per the definition of a
character:
*char**any-Unicode-character-*
*except-**"**-or-**\**-or-*
*control-character*
*\"*
*\\*
*\/*
*\b*
*\f*
*\n*
*\r*
*\t*
*\u* *four-hex-digits*
Thus the following object is valid:
{
"My.Key" : "My.Value"
}
The behaviour you are referring to is for use within script (specifically
JavaScript). One of the advantages of sending JSON to a web page is that it
is very easy to convert JSON to a JavaScript object, e.g:
var json = "{ \"key\" : \"value\"}"; // could come from a remote service
var x = eval(json);
Alert(x.key);
Alert(x["key"]);
Alert(["x"].key); // this is not actually valid because ["x"] means nothing
in this context
I wouldn't want a potential use case for Pivot to be invalidated because
> Pivot is unable to consume the JSON output that a non-compliant web service
> produces.
Unfortunately, the case at the moment is that we don't seem to be able to
consume valid JSON, as per Sandro's example. Though I agree we should be
robust enough to consume non-compliant output as well.
> It also seems to be a common sentiment that the JSON standard should
> support non-quoted keys.
>
Again, that's not something I'm aware of. The spec is clearly laid out on
the JSON website:
http://json.org/
So, keys are always strings (which are quoted) and values could be strings
or other types (i.e. one of number, object, array, the unquoted literal
"false", the unquoted literal "true" or the unquoted literal "null").
Cheers,
Chris
2009/4/8 Greg Brown <[email protected]>
> >To be honest, I'm not aware of what Pivot uses being a common extension,
> >I've only ever seen it in Pivot.
>
> JavaScript generally drops the quotes:
>
> var foo = {bar:100};
>
> I find this more readable.
>
>
>