Closed jovanpop-msft closed 7 years ago
Actually that is not true, if you check the rfc7159 you will see that it is not necessary for the JSON text to be only array or object.
Hi, rfc7159 describes JSON format, i.e. the elements that can be in JSON. Could you take a look at https://tools.ietf.org/html/rfc4627 that is referenced from rfc7159, that describes JSON grammar. Look at the following section:
JSON Grammar
A JSON text is a sequence of tokens. The set of tokens includes six structural characters, strings, numbers, and three literal names. A JSON text is a serialized object or array.
JSON-text = object / array
Also, on http://json.org/ you can find definition:
JSON is built on two structures:
- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
Any JavaScript/Ajax call would expect JSON response as array/object. I agree that this might be unclear, so maybe you can create separate file with grammar above so people can choose the one they need.
I am aware of the previous RFC, here is the relevant portion from rfc7159.
Note that certain previous specifications of JSON constrained a JSON text to be an object or an Implementations that generate only objects or arrays where a JSON text is called for will be interoperable in the sense that all implementations will accept these as conforming JSON texts.
That said, I am happy to add your grammar in since it may be more appropriate for the JS/Ajax call responses. Can you create a PR and add it to https://github.com/codelion/gramtest/tree/master/src/test/resources folder?
Current example for JSON grammar generates number and strings which are not valid JSON text. Only object or array can be the root JSON object. Probably correct syntax would be: