3 ms·
JSON objects can have duplicate keys/names
- dragonwriter 13y agoRight. If you read the beginning of the RFC where it defines what an object is, its an "unordered collection of name/value pairs". Not, it should be emphasized, "an associative array mapping names to values". There are quite a few applications where it is useful to parse JSON into objects that are associative arrays mapping names to values, in which case you need to either avoid duplicate names or resolve them somehow ("last-defined-wins" seems to be the most common rule.) OTOH, its not too hard to imagine applications that would be more natural using the "unordered collection" model without interpreting JSON objects as associative arrays (a hypothetical JSON serialization of HTML, where JSON object member names correspond to HTML tag names comes to mind.) But RFC also says names in an object SHOULD (in the RFC 2119 sense) be unique, which means (to adapt the language of RFC 2119 to the specific case at issue) that "there may exist valid reasons in particular circumstances to [have duplicate names], but the full implications must be understood and carefully weighed before [using duplicate names]."