Home > Software design >  A Key-Value pair containing Key-Value pair in JSON?
A Key-Value pair containing Key-Value pair in JSON?

Time:09-27

Should this be accepted as a valid JSON object?

{"name":"First":"Last"}

Assuming that {"name": something else} where something else is a key-value pair : <"First":"Last">.

I've seen some threads that discuss this and I've found that it's certainly valid to use syntax like {"name":{"First":"Last"}} but in this case it's not a key:value pair of key:value pair, this is going to be a <key-value pair of <object of < key-value pair > >>.

Should a pure <key:value pair of <key:value pair>> be accepted as a valid object key-value pair by the standard?

CodePudding user response:

JSON does not have a "key-value" type. So, no, that's not valid syntax and it doesn't correspond to any JSON value.

You could use either of the following:

  • {"name": ["Jane", "Doe"]}
  • {"name": {"first": "Jane", "last": "Doe"}

I don't see how you could describe "Jane": "Doe" as a key-value pair, but perhaps that's not what you meant. I think my second example comes close to what you're talking about, but maybe not.

  • Related