12/9/2023 0 Comments Do not duplicate meaning![]() ![]() Posting and answer because there is a lot of outdated ideas and confusion about the standards. But when deserializing some JSON object into a std::multimap it would make sense to accept duplicate keys as normal. When deserializing some JSON object into a std::map it would make sense to refuse duplicate keys. Here are two examples related to the C++ standard library. That most implementations of JSON libraries do not accept duplicate keys does not conflict with the standard, because of the first quote. It does not make any mention of duplicate keys being invalid or valid, so according to the specification I would safely assume that means they are allowed. A singleĬomma token separates a value from a following name. A single colon token follows each name, separating the name from the value. 2), the specification for a JSON object:Īn object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs.Ī name is a string. Such standards may require specific behaviours. Imposing restrictions on various encoding details. It is expected that other standards will refer to this one, strictly adhering to the JSON text format, while Trying to parse a string with duplicated names with the Java implementation by Douglas Crockford (the creator of JSON) results in an exception: : Duplicate key "status" at In the case where there are duplicate name Strings within an object, lexically preceding values for the same key shall be overwritten. Object, and some implementations report all of the name/value pairs,Īlso, as Serguei pointed out in the comments: ECMA-262 "ECMAScript® Language Specification", reads: Other implementations report an error or fail to parse the Many implementations report the last name/value pair Unique, the behavior of software that receives such an object is That all software implementations receiving that object will agree on RFC 8259 explains why unique names (keys) are good:Īn object whose names are all unique is interoperable in the sense Particular item, but the full implications must be understood andĬarefully weighed before choosing a different course. May exist valid reasons in particular circumstances to ignore a SHOULD This word, or the adjective "RECOMMENDED", mean that there In this context SHOULD must be understood as specified in BCP 14: ![]() The names within an object SHOULD be unique. However, RFC 8259 "The JavaScript Object Notation (JSON) Data Interchange Format" says: ![]() The long answer: It depends on what you call valid.ĮCMA-404 "The JSON Data Interchange Syntax" doesn't say anything about duplicated names (keys). The short answer: Yes but is not recommended. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |