JSON Duplicate Keys
douglas at crockford.com
Thu Jun 6 04:42:02 PDT 2013
On 6/6/2013 4:34 AM, Anne van Kesteren wrote:
> On Thu, Jun 6, 2013 at 12:29 PM, Douglas Crockford
> <douglas at crockford.com> wrote:
>> The JSON RFC says
>> The names within an object SHOULD be unique.
>> to mean DON'T HAVE TO. In a perfect world, we would change the SHOULD to
>> MUST, but we can't. Interoperability and security concerns demand that we
>> specify what happens when keys are duplicated. So we may end up with
>> something like this:
>> The names within an object SHOULD be unique. If a key is duplicated,
>> a parser SHOULD reject. If it does not reject, it MUST take only the
>> last of the duplicated key pairs.
>> Does anyone see a problem with this?
> SHOULD reject seems too strong given that we know perfectly well we
> cannot do that. MAY seems much more reasonable or maybe MUST either
> reject or take the last of the duplicated key pairs (decision up to
> the parser API specification).
The current RFC already says SHOULD. We don't have to weaken that. But
we should be explicit about what a parser should do if it decides to
accept away. The sentence
If a key is duplicated, a parser SHOULD reject.
is not a change. It is implied by the first statement. The thing that
is a change is the third statement
If it does not reject, it MUST take only the last of the duplicated
More information about the es-discuss