jsonjsonlint

Which form is valid between starting with square and curly brackets?


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

Wrong json:

  1. [ "name": {} ]

True json:

  1. { "name": {} }

Can any one explain why first one is wrong while second one true.


Solution

  • [ 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).