-
-
Notifications
You must be signed in to change notification settings - Fork 594
Closed
Description
jsonschema already have a function validate
to validate a raw dict with a schema.
To explain what I mean, for example, there is a dict:
raw_dict = {
"latitude": 48.858093,
"longitude": 2.294694,
"extra_key": "value1"
}
and a schema:
schema = {
"id": "https://example.com/geographical-location.schema.json",
"$schema": "http://json-schema.org/draft-06/schema#",
"title": "Longitude and Latitude Values",
"description": "A geographical coordinate.",
"required": [ "latitude", "longitude" ],
"type": "object",
"properties": {
"latitude": {
"type": "number",
"minimum": -90,
"maximum": 90
},
"longitude": {
"type": "number",
"minimum": -180,
"maximum": 180
}
}
}
Now I want a function which like:
def reduce(instance, schema):
...
return new_instance
>>> reduce(raw_dict, schema)
>>> raw_dict = {
"latitude": 48.858093,
"longitude": 2.294694
}
the reduce
function validate the raw_dict and pass it ,then convert it to the result which fit the schema, if the dict is not passed, it behaves like validate
, raise an error.
If this function is allowed to add into jsonschema, I can take some time to write it.
Metadata
Metadata
Assignees
Labels
No labels