I want to know whether there is a method in which I can generate sample json output based on a json schema input.
for example :-
input => { "title": "Example Schema", "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", "type": "integer", "minimum": 0 } }, "required": ["firstName", "lastName"] } output => { "firstName" : "RandomFirstName", "lastName" : "RandomLastName" } I have a large Json Schema with plenty of validations so to generate a sample valid json I could either create one manually using either Java or just a type it into a file. Is there a better way available ?
75 Answers
You can try the JSON Schema Faker. It will take a schema and generate/output a JSON object that will validate against the schema.
3JSONBuddy can do this for you. It is a Windows desktop JSON editor and generates live JSON sample data while you are editing your schema.
fake-schema-cli is another option you can use.
Example: fake-schema file-input-schema.json > output.json.
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 - .
You can also use the ModelObject in Adobe Ride (full disclosure: self-plug here). Point the ModelObject (or a subclass thereof) to a schema in your java project resources:
You can also use the Ride Fuzzer Lib to easily tests sending negative data into the schema nodes (based on an array of OWASP and google injection test strings, and other various types data):