JSON模式生成器Python [英] JSON Schema Generator Python
本文介绍了JSON模式生成器Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用此资源来生成架构 https://github.com/wolverdude/GenSON/
I am using this resource to generate the schema https://github.com/wolverdude/GenSON/
我有以下JSON文件
{
'name':'Sam',
},
{
'name':'Jack',
}
等等...
我想知道如何迭代一个大的JSON文件.我想解析每个JSON文件并将其传递给GENSON以生成架构
I am wondering how to iterate over a large JSON file. I want to parse each JSON file and pass it to GENSON to generate schema
{
"$schema": "http://json-schema.org/schema#",
"type": "object",
"properties": {
"name": {
"type": [
"string"
]
}
},
"required": [
"name"
]
}
推荐答案
我认为您应该:
import json
from genson import SchemaBuilder
builder = SchemaBuilder()
with open(filename, 'r') as f:
datastore = json.load(f)
builder.add_object(datastore )
builder.to_schema()
文件名是您的文件路径.
Where filename is your file path.
这篇关于JSON模式生成器Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文