generate schema from json python

Solutions on MaxInterview for generate schema from json python by the best coders in the world

showing results for - "generate schema from json python"
Richie
20 Feb 2016
1#Example usage of generating python code
2from jsonschemacodegen import python as pygen
3import json
4
5with open('schema.json') as fp:
6    generator = pygen.GeneratorFromSchema('output_dir')
7    generator.Generate(json.load(fp), 'Example', 'example')
8
9#using the generated code looks like
10
11import example
12import json
13
14jsonText = '["an example string in an array"]'
15
16obj = example.Example(json.loads(jsonText))
17
18print(json.dumps(obj, default=lambda x: x.Serializable()))