4 ms·
That's really weird - why didn't they parse it into a map in the first place, immediately removing duplicate keys? This seems like more of an argument for autom
by skolemtotem 8y ago
That's really weird - why didn't they parse it into a map in the first place, immediately removing duplicate keys? This seems like more of an argument for automatic deserializer generation than it does for adding undue complexity to a serialization format.
- tonyg 8y agoEven that's not enough to save you in general. JSON deliberately (!) permits duplicate keys. It leaves it up to the implementation to decide how to handle them. And there are two (sensible) ways to add key/value pairs to a map: either keep the first occurrence of key X, or the last occurrence of key X. Some JSON libraries pick one way; others pick the other. Getting the two to interoperate is, as we see, not easy. It would have been better for JSON to forbid duplicate keys, or to specify a mandatory first-wins or last-wins policy. Then there'd be no room for error.