JSON Schema allOf & JSON Parser duplicate‑key handling: interoperability concern
0 reputation · 20 Jun 2024, 16:34 UTC
Interoperability between JSON Schema allOf and JSON parsers with duplicate keys
JSON Schema’s allOf keyword allows a schema to combine constraints from several subschemas. However, the JSON specification does not define how duplicate keys in an object should be treated. Most parsers silently accept the last occurrence, but some libraries preserve the first or raise an error. When a document containing duplicate keys is validated against an allOf schema, it is unclear which key value should be used by the validator, especially if the duplicate keys belong to different subschemas. This ambiguity can lead to subtle bugs when systems assume different semantics, making the interaction between allOf and duplicate‑key handling an unresolved decision that affects both validators and consumers.
What value should a validator consider when duplicate keys appear in a document validated against an allOf schema?
Should allOf subschemas enforce unique property names to avoid duplicate key conflicts?
How can libraries expose the duplicate key resolution strategy to consumers to ensure consistent interpretation?