pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
466 stars 134 forks source link

Validation Error from null field #254

Closed ZenixineZ closed 1 year ago

ZenixineZ commented 1 year ago

Schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "field1": { "type": "string" },
    "field2": { "type": "string" }
  },
  "required": ["field1"]
}

Object:

{
  "field1": "test", 
  "field2": null 
}

Error: At /field2 of null - unexpected instance type

Is there anyway for it to allow null values for non-required fields?

pboettch commented 1 year ago

This is more a question for Stackoverflow.

Try: "field2": { "type": ["null", "string"] }

ZenixineZ commented 1 year ago

My god I feel foolish. Thank you for the response and sorry I bothered you