我们有这个json模式草案。我想获得我的JSON数据的样本,并为JSON模式生成一个框架,我可以手动返工,添加像描述,要求等东西,这不能从具体的例子推断。

例如,在我的输入example.json中:

{
    "foo": "lorem", 
    "bar": "ipsum"
}

我将运行我的json_schema_generator工具,并将得到:

{ "foo": {
    "type" : "string",
    "required" : true,
    "description" : "unknown"
  },
  "bar": {
    "type" : "string",
    "required" : true,
    "description" : "unknown"
  }
}

这个例子是手动编码的,所以可能会有错误。 是否有任何工具可以帮助我转换JSON -> JSON模式?


当前回答

总结其他答案,以下是迄今为止提出的JSON模式生成器:

在线:

https://www.liquid-technologies.com/online-json-to-schema-converter(1个输入) http://www.jsonschema.net(1个输入) https://easy-json-schema.github.io(1个输入)

Python:

https://github.com/gonvaled/jskemator(1个输入,但允许迭代) https://github.com/perenecabuto/json_schema_generator(1个输入) https://github.com/rnd0101/json_schema_inferencer(我认为1个输入) https://pypi.python.org/pypi/genson/(多输入) https://pypi.python.org/pypi/skinfer(多输入)

NodeJS:

https://github.com/Nijikokun/generate-schema(多个输入(传递对象数组)) https://github.com/easy-json-schema/easy-json-schema(1个输入) https://github.com/aspecto-io/genson-js(多输入)

Ruby:

https://github.com/maxlinc/json-schema-generator(1个输入)

其他回答

generate-schema (NPM | Github)使用JSON对象从中生成模式,一个输出是JSON模式,它是用Node.js编写的,并带有一个REPL和ClI工具,用于将文件管道到。

完全披露:我是作者:)

你可能在找这个:

http://www.jsonschema.net

它是一个在线工具,可以从JSON字符串自动生成JSON模式。您可以轻松地编辑模式。

总结其他答案,以下是迄今为止提出的JSON模式生成器:

在线:

https://www.liquid-technologies.com/online-json-to-schema-converter(1个输入) http://www.jsonschema.net(1个输入) https://easy-json-schema.github.io(1个输入)

Python:

https://github.com/gonvaled/jskemator(1个输入,但允许迭代) https://github.com/perenecabuto/json_schema_generator(1个输入) https://github.com/rnd0101/json_schema_inferencer(我认为1个输入) https://pypi.python.org/pypi/genson/(多输入) https://pypi.python.org/pypi/skinfer(多输入)

NodeJS:

https://github.com/Nijikokun/generate-schema(多个输入(传递对象数组)) https://github.com/easy-json-schema/easy-json-schema(1个输入) https://github.com/aspecto-io/genson-js(多输入)

Ruby:

https://github.com/maxlinc/json-schema-generator(1个输入)

For the offline tools that support multiple inputs, the best I've seen so far is https://github.com/wolverdude/GenSON/ I'd like to see a tool that takes filenames on standard input because I have thousands of files. However, I run out of open file descriptors, so make sure the files are closed. I'd also like to see JSON Schema generators that handle recursion. I am now working on generating Java classes from JSON objects in hopes of going to JSON Schema from my Java classes. Here is my GenSON script if you are curious or want to identify bugs in it.

#!/bin/sh
ulimit -n 4096
rm x3d*json
cat /dev/null > x3d.json
find ~/Downloads/www.web3d.org/x3d/content/examples -name '*json' -      print| xargs node goodJSON.js | xargs python bin/genson.py -i 2 -s     x3d.json >> x3d.json
split -p '^{' x3d.json x3d.json
python bin/genson.py -i 2 -s x3d.jsonaa -s x3d.jsonab /Users/johncarlson/Downloads/www.web3d.org/x3d/content/examples/X3dForWebAuthors/Chapter02-GeometryPrimitives/Box.json > x3dmerge.json 

在https://github.com/krg7880/json-schema-generator上有一个支持json模式v4的nodejs工具

它既可以作为命令行工具,也可以作为nodejs库:

var jsonSchemaGenerator = require('json-schema-generator'),
    obj = { some: { object: true } },
    schemaObj;

schemaObj = jsonSchemaGenerator(json);