xeipuuv / gojsonschema

An implementation of JSON Schema, draft v4 v6 & v7 - Go language
2.53k stars 356 forks source link

How to validate Duplicate field with gojsonschema? #204

Closed Houlton closed 6 years ago

Houlton commented 6 years ago

This is my json content: { "name" : "tony", "name" : "jane" } There are two same fields, but Validate OK.

handrews commented 6 years ago

Per RFC 8259, the behavior of duplicate fields is undefined.

Per the latest JSON Schema draft, objects in the JSON Schema data model cannot have multiple keys, so the behavior for a JSON document with multiple keys is undefined.

Houlton commented 6 years ago

Hi, So, I can't use gojsonschema to detect multiple keys, am I right?

handrews commented 6 years ago

@Houlton you cannot use any conforming JSON Schema implementation to detect multiple keys. Multiple keys are not an interoperable feature of JSON and therefore they are not covered by the specification. All implementations should have this limitation, because the IETF JSON working group that produced RFC 8259 and its predecessors chose not to address duplicate keys in an interoperable way. JSON Schema therefore does not have any reliable way to detect or otherwise interact with them.

Houlton commented 6 years ago

Got it . Thank you very much for your explanation.