Skip to content

Instantly share code, notes, and snippets.

@abulte
Last active May 13, 2022 14:58
Show Gist options
  • Save abulte/27767abd008121144447f66c7bb4ce16 to your computer and use it in GitHub Desktop.
Save abulte/27767abd008121144447f66c7bb4ce16 to your computer and use it in GitHub Desktop.
validata-geojson-stream
import collections
import json
import json_stream
import jsonschema
from jsonschema import Draft7Validator
with open("schema_amenagements_cyclables.json") as ifile:
schema = json.load(ifile)
# get schema for one item
subschema = schema["properties"]["features"]["items"]["properties"]["properties"]
errors = collections.defaultdict(int)
with open("france-20220224.geojson") as f:
data = json_stream.load(f)
count = 0
v = Draft7Validator(subschema)
for feature in data["features"].persistent():
count += 1
print(count)
props = dict(feature["properties"])
for e in v.iter_errors(props):
errors[e.message] += 1
print(errors)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment