matrix-org / matrix-spec

The Matrix protocol specification
Apache License 2.0
186 stars 94 forks source link

Canonical JSON does not specify how to handle duplicate key values #1246

Open neilalexander opened 2 years ago

neilalexander commented 2 years ago

Different implementations have different ideas on how to handle duplicate keys in JSON. They shouldn't appear in theory, but there's nothing to stop you from doing something like:

{
  "one": 1,
  "two": 2,
  "two": 3
}

How this is handled varies between implementations (Go will take the last value, Swift will take the first etc).

We don't have anything in the spec that says how to handle this case appropriately.

(created from #1232)

richvdh commented 1 year ago

The first step in solving this is (in the absence of dropping canonicaljson altogether) is to make a decision on the "correct" behaviour here. We can then figure out how to roll it out.

To open discussion: it feels like the most "correct" thing to do is to simply forbid duplicate keys (in the same way that we forbid floats, or numbers greater than 2**53). But maybe that is a PITA to implement?

turt2live commented 1 year ago

fwiw, RFC 8785 explictly declares duplicate keys as invalid.