json schema python code example
Example: generate schema from json python
#Example usage of generating python code
from jsonschemacodegen import python as pygen
import json
with open('schema.json') as fp:
generator = pygen.GeneratorFromSchema('output_dir')
generator.Generate(json.load(fp), 'Example', 'example')
#using the generated code looks like
import example
import json
jsonText = '["an example string in an array"]'
obj = example.Example(json.loads(jsonText))
print(json.dumps(obj, default=lambda x: x.Serializable()))