Skip to content

does jsonschema support verifying optional field in json? #567

@jm18919

Description

@jm18919

I am trying to figure out whether jsonschema supporting verifying optional field in json or not. I tried the following code:

from jsonschema import validate

# your code here
schema = {
    "type" : "object",
    "properties" : {
        "price" : {"type" : "number", "required": false},
        "name" : {"type" : "string"},
    },
}

validate({"name" : "Eggs", "price" : 123.123}, schema)

I have this error:

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-6a64e78dd26e> in <module>
      5     "type" : "object",
      6     "properties" : {
----> 7         "price" : {"type" : "number", "required": false},
      8         "name" : {"type" : "string"},
      9     },

NameError: name 'false' is not defined

So this feature isn't supported yet?
I found related question here

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions