Hacker News new | ask | show | jobs
by masklinn 4698 days ago
> There is no guarantee that a JSON parser will give you the right value if there are two of the same keys in the same scope.

In fact, reading the RFC:

> The names within an object SHOULD be unique.

I'm pretty sure an implementation could refuse to parse the form altogether.

1 comments

SHOULD is a horrible word to put in any spec if it doesn't specify what the result will be if that recommendation is violated
SHOULD is defined in RFC 2119 as

    3. SHOULD   This word, or the adjective "RECOMMENDED", mean that there
       may exist valid reasons in particular circumstances to ignore a
       particular item, but the full implications must be understood and
       carefully weighed before choosing a different course.
The consequences are undefined, I feel, for a reason. You can't put them all down on paper, it depends on what all the parsers do. The parsers can accept or reject things with duplicate keys, or they can play a nice little ditty through the speakers.

All it means is a parser isn't required to reject JSON with multiple keys. It can, however, do whatever the fuck it wants with them.

If the wording was precise, then it should be a MUST. SHOULD indicates a terrible world of unknown consequences.