Most place the JSON is in format like
{
color: \"red\",
value: \"#f00\"
}
Or
[
{ color: \"red\", value: \"#f0
{ "astring" }
is not valid JSON and neither is "astring"
or astring
, as we need both a key and a value, e.g. { KEY : VALUE }
where KEY
is always a string and VALUE
can be a string, number, boolean, or null.
From the spec:
Yes, as the spec says, JSON can be a top level primitive value without an object wrapping it. – Andy Ray
If I understood it correctly, that comment is not correct. Valid JSON is never a top-level primitive value by itself. If you're still confused, this should clear things up:
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
These are the six structural characters:
begin-array = ws %x5B ws ; [ left square bracket
begin-object = ws %x7B ws ; { left curly bracket
end-array = ws %x5D ws ; ] right square bracket
end-object = ws %x7D ws ; } right curly bracket
name-separator = ws %x3A ws ; : colon
value-separator = ws %x2C ws ; , comma
Insignificant whitespace is allowed before or after any of the six structural characters.