-7

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.

Paolo Forgia
  • 6,572
  • 8
  • 46
  • 58
Vasant
  • 3,475
  • 3
  • 19
  • 33
  • *can any one differentiate why first one is wrong* Because it doesn't match the spec, besides not meaning anything. If you had used a validator/parser which reports character position information, you would see that the error is reported at the position of the colon. –  Aug 27 '16 at 11:43

1 Answers1

3

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

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875