JSON Duplicate Keys

Alexandre Morgaut Alexandre.Morgaut at 4d.com
Fri Jun 7 00:35:28 PDT 2013


On 6 juin 2013, at 15:45, Rick Waldron wrote:

On Thu, Jun 6, 2013 at 9:31 AM, Jeremy Darling <jeremy.darling at gmail.com<mailto:jeremy.darling at gmail.com>> wrote:
Copying in from another post I sent.  Instead of amending SHOULD to allow parsers to throw new errors why not have them emit collections when duplication is found?

Duplicate Keys should never have been allowed in the spec in the first place (most all key/value stores don't allow it) or if they were allowed when decomposed to JS objects they should have created arrays of values much like most frameworks do for duplicate keys in the HTTP headers.

Thus, and typing this makes my skin crawl and my head hurt:

{
  "myKey": "Value 1",
  "myKey": 2
}

Becomes, upon parse:

{
  "myKey": ["Value 1", 2]
}

All values have now been accounted for. nothing has been created or lost, and code that didn't take into account multiple keys but did type checking on values will fail or adapt gracefully.

This breaks extant data value invariants. Ignoring the original question and addressing only this example, let's say the expected value was a string (your example shows a string and a number)

  var parsed = JSON.parse(data);
  parsed.myKey.toUpperCase();
  // TypeError

This is web breaking.

Rick

I agree with Rick and would add that if myKey can legitimately be an array, with any type of elements, the receiver as no way to know what was the original message

In some cases, as to set an email "To" field, a JSON message can provide a string for an unique email or an array of emails. This is a very simple example which may be solved with regex analyses updates but:
- this may break existing implementations
- some more complex examples may not be detectable

[cid:ab50c5.png at 00a2dc9f.4681140a]
Alexandre Morgaut
Wakanda Community Manager
Email : Alexandre.Morgaut at 4d.com<mailto:Alexandre.Morgaut at 4d.com>
Web :   www.4D.com<http://www.4D.com>

4D SAS
60, rue d'Alsace
92110 Clichy - France
Standard :      +33 1 40 87 92 00




-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130607/cae4df0e/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ab50c5.png
Type: image/png
Size: 4628 bytes
Desc: ab50c5.png
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130607/cae4df0e/attachment-0001.png>


More information about the es-discuss mailing list