Vasant Vasant - 9 months ago 41
JSON Question

Which Json form is valid in between starting from square brackets and starting from curly brackets?

I have two json form.i tried to validate in jsonlint.It show error for first &it validate to second json.

Wrong json:

"name": {}

True json:

"name": {}

can any one differentiate why first one is wrong & second one true.


[ starts an array initializer. Valid entries are values separated by comments. Example:

["one", 2, "three"]

{ starts an object initializer. Valid entries are name/value pairs where each pair is a names in double quotes followed by a colon (:) followed by any valid value. Examples:

{"name": "value"}

{"name": {}}

{"name": ["one", 2, "three"]}

All of this is covered by the website and the standard.

Your first example is invalid because it's trying to define a name/value pair where a value is expected (in an array entry).