python - JSON 模式生成器 Python
问题描述
我正在使用此资源生成架构https://github.com/wolverdude/GenSON/
我有以下 JSON 文件
{
'name':'Sam',
},
{
'name':'Jack',
}
很快 ...
我想知道如何迭代一个大的 JSON 文件。我想解析每个 JSON 文件并将其传递给 GENSON 以生成模式
{
"$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()
其中文件名是您的文件路径。
推荐阅读
- jquery - 不明白它是如何工作的
- ruby-on-rails - 有条件的订单元素
- android - 如何阅读 FIFA/ESPN 的 RSS 提要?
- android - 丢失片段更改的数据
- javafx - 无法获取文本字段输入 [JavaFX]
- python - 在 str 对象上使用 'to_datetime' - 为了更改数据框列名
- go - GoConvey 自定义断言未按预期工作
- c# - multipart/form-data post api 在 hcloud 上不起作用
- c++ - 每个线程使用 boost::asio::deadline_timer 不起作用
- apache-kafka - Ksql:左连接显示流中的列但不显示表