This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 24436 - [XSLT 3.0] Poorly-designed JSON example
Summary: [XSLT 3.0] Poorly-designed JSON example
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XSLT 3.0 (show other bugs)
Version: Last Call drafts
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-29 09:52 UTC by Michael Kay
Modified: 2014-02-24 15:51 UTC (History)
1 user (show)

See Also:


Attachments

Description Michael Kay 2014-01-29 09:52:23 UTC
The JSON example in 21.2.1 is rather inelegant in that the only array it contains (the phone numbers) contains a single entry (a map), and it's not clear why an array is needed here. It's legal JSON, but not a very good example.
Comment 1 Florent Georges 2014-01-30 20:06:41 UTC
(In reply to Michael Kay from comment #0)
> The JSON example in 21.2.1 is rather inelegant in that the only array it
> contains (the phone numbers) contains a single entry (a map)

It looks like it is an adaptation of an example I've sent on the mailing list, which I took from the Wikipedia page for JSON <http://en.wikipedia.org/wiki/JSON>.  But the value of the array has been changed from:

    "phone numbers" :  [ 
       { "type": "home", 
         "number": "212 732-1234"
       },
       { "type": "fax", 
         "number": "646 123-4567"
       }
    ]

to:

    "phone numbers" :  [ 
       { "home": "212 732-1234", 
         "fax": "646 123-4567"
       }
    ]

The first one looks legitimate to me, WRT having an array.  I can try and come with another example, but this one (with the above modification) looks good to me.

By the way, the example also uses spaces in the names.  As far as I can see, this is valid syntax, but I guess it would generate an error if someone tries to parse it as a Javascript object.  Do we want to remove spaces in names?
Comment 2 Florent Georges 2014-02-04 18:54:29 UTC
Another candidate, self-explanatory, with strings, numbers, a date-time, a boolean, null, objects, and legitimate arrays:

    {
      "desc"    : "Distances between several cities, in kilometers.",
      "updated" : "2014-02-04T18:50:45",
      "uptodate": true
      "author"  : null
      "cities"  : {
        "Brussels": [
          {to: "London",    distance: 322},
          {to: "Paris",     distance: 265},
          {to: "Amsterdam", distance: 173}
        ],
        "London": [
          {to: "Brussels",  distance: 322},
          {to: "Paris",     distance: 344},
          {to: "Amsterdam", distance: 358}
        ],
        "Paris": [
          {to: "Brussels",  distance: 265},
          {to: "London",    distance: 344},
          {to: "Amsterdam", distance: 431}
        ],
        "Amsterdam": [
          {to: "Brussels", distance: 173},
          {to: "London",   distance: 358},
          {to: "Paris",    distance: 431}
        ]
      }
    }
Comment 3 Michael Kay 2014-02-04 23:07:21 UTC
Thanks. But the "to" and "distance" should be in quotes, surely?
Comment 4 Florent Georges 2014-02-11 21:42:02 UTC
I used plain JavaScript notation, which does not require to quote object member names when they follow the rules for variable names. But from http://tools.ietf.org/html/rfc4627, it seems you are right and quotes are indeed required for names, always.
Comment 5 Michael Kay 2014-02-20 16:46:25 UTC
I have used the example in comment #2, with quotes added to make it legal.