Json format defines keys and values. And how about the following
{
"Kill"
}
Is it an acceptable json format?
CodePudding user response:
The original JSON introduction is extremely straight-forward, including diagrams of the possible constructions. Among the text content is this:
An object is an unordered set of name/value pairs. An object begins with
{
left brace and ends with}
right brace. Each name is followed by:
colon and the name/value pairs are separated by,
comma.
The later ECMA-404 standard includes similar wording:
An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. A name is a string. A single colon token follows each name, separating the name from the value. A single comma token separates a value from a following name.
The IETF standard, RFC 8259 puts it this way:
An object structure is represented as a pair of curly brackets surrounding zero or more name/value pairs (or members). A name is a string. A single colon comes after each name, separating the name from the value. A single comma separates a value from a following name. The names within an object SHOULD be unique.
In every case, note that every key is followed by a colon and a value. Since there is no colon following the key in your example, it is not valid JSON.
CodePudding user response:
No, in JSON notation, an object is an unordered set of key/value pairs, and both the key and the value are required elements.
If the object you've shown is the only thing you want to have in your JSON text, you could just remove the object wrapper:
"Kill"
That's perfectly valid JSON. (There was a time when JSON was defined as requiring the outermost element to be an object or an array, but that hasn't been true for many, many years.)