We have this json schema draft. I would like to get a sample of my JSON data and generate a skeleton for the JSON schema, that I can rework manually, adding things like description, required, etc, which can not be infered from the specific examples.
For example, from my input example.json
:
{
"foo": "lorem",
"bar": "ipsum"
}
I would run my json_schema_generator tool and would get:
{ "foo": {
"type" : "string",
"required" : true,
"description" : "unknown"
},
"bar": {
"type" : "string",
"required" : true,
"description" : "unknown"
}
}
This example has been coded manually, so it has maybe errors. Is there any tool out there which could help me with the conversion JSON -> JSON schema?
Seeing that this question is getting quite some upvotes, I add new information (I am not sure if this is new, but I couldn't find it at the time)
After several months, the best answer I have is my simple tool. It is raw but functional.
What I want is something similar to this. The JSON data can provide a skeleton for the JSON schema. I have not implemented it yet, but it should be possible to give an existing JSON schema as basis, so that the existing JSON schema plus JSON data can generate an updated JSON schema. If no such schema is given as input, completely default values are taken.
This would be very useful in iterative development: the first time the tool is run, the JSON schema is dummy, but it can be refined automatically according to the evolution of the data.
GenSON (PyPI | Github) is a new JSON Schema generator that can generate a single schema from multiple objects. You can also merge schemas with it. It is written in Python and comes with a CLI tool.
(Full disclosure: I'm the author.)
There's a nodejs tool which supports json schema v4 at https://github.com/krg7880/json-schema-generator
It works either as a command line tool, or as a nodejs library:
There's a python tool to generate JSON Schema for a given JSON: https://github.com/perenecabuto/json_schema_generator
json-schema-generator is a neat Ruby based JSON schema generator. It supports both draft 3 and 4 of the JSON schema. It can be run as a standalone executable, or it can be embedded inside of a Ruby script.
Then you can use json-schema to validate JSON samples against your newly generated schema if you want.