You can try the JSON Schema Faker. It will take a schema and generate/output a JSON object that will validate against the schema.
Code available on githubcom
Answer from Eric Olson on Stack OverflowYou can try the JSON Schema Faker. It will take a schema and generate/output a JSON object that will validate against the schema.
Code available on githubcom
My team and I have created an online tool that allows you to parse JSON schema and generate an array of JSON data that complies to the schema. You can save it as .json file and parse it to your app with a Java parser.
The tool is called Mock turtle - https://mockturtle.net .
Videos
Summarising the other answers, here are the JSON schema generators proposed so far:
Online:
- https://www.liquid-technologies.com/online-json-to-schema-converter (1 input)
- http://www.jsonschema.net (1 input)
- https://easy-json-schema.github.io (1 input)
- https://json.ophir.dev/ (1 input, nice UI)
Python:
- https://github.com/gonvaled/jskemator (1 input but allows iteration)
- https://github.com/perenecabuto/json_schema_generator (1 input)
- https://github.com/rnd0101/json_schema_inferencer (1 input I think)
- https://pypi.python.org/pypi/genson/ (multiple inputs)
- https://pypi.python.org/pypi/skinfer (multiple inputs)
NodeJS:
- https://github.com/Nijikokun/generate-schema (multiple inputs (pass object array))
- https://github.com/easy-json-schema/easy-json-schema (1 input)
- https://github.com/aspecto-io/genson-js (multiple inputs)
Ruby:
- https://github.com/maxlinc/json-schema-generator (1 input)
You might be looking for this:
http://www.jsonschema.net
It is an online tool that can automatically generate JSON schema from JSON string. And you can edit the schema easily.
https://github.com/ghandic/jsf
Use jsf along with fake data generators to provide consistent and meaningful fake data for your system.
Main Features
Provides out of the box data generation from any JSON schema ๐ฆ
Extendable custom data providers using any lambda functions ๐
Multi level state for dependant data (eg multiple objects sharing value, such as children with same surname) ๐ค
Inbuilt validation of fake JSON produced โ
In memory conversion from JSON Schema to Pydantic Models with generated examples ๐คฏ
Seamless integration with FastAPI ๐
Installation
$ pip install jsf ---> 100%
Usage
Basic ๐
from jsf import JSF
faker = JSF(
{
"type": "object",
"properties": {
"name": {"type": "string", "$provider": "faker.name"},
"email": {"type": "string", "$provider": "faker.email"},
},
"required": ["name", "email"],
}
)
fake_json = faker.generate()Results in ...
{
'name': 'Jesse Phillips',
'email': 'xroberson@hotmail.com'
}From JSON file ๐
from jsf import JSF
faker = JSF.from_json("demo-schema.json")
fake_json = faker.generate()<details markdown="1"> <summary>Or run stright from the <code>commandline</code>...</summary>
Native install
jsf --schema src/tests/data/custom.json --instance wow.json
Docker
docker run -v $PWD:/data challisa/jsf jsf --schema /data/custom.json --instance /data/example.json
</details>
FastAPI Integration ๐
Create a file main.py with:
from jsf import JSF
from fastapi import FastAPI
app = FastAPI(docs_url="/")
generator = JSF.from_json("custom.json")
@app.get("/generate", response_model=generator.pydantic())
def read_root():
return generator.generate()Run the server with:
<div class="termy">
$ uvicorn main:app --reload INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process [28720] INFO: Started server process [28722] INFO: Waiting for application startup. INFO: Application startup complete.
Navigate to http://127.0.0.1:8000 and check out your endpoint. Notice the following are all automatically created:
Schema with descriptions and examples
Example response
Data generation by clicking "try it out"