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 ?
Declaring a unique identifier It is also best practice to include an $id property as a unique identifier for each schema. For now, just set it to a URL at a domain you control, for example: { "$id": "http://yourdomain.com/schemas/myschema.json" }
JSON (JavaScript Object Notation) is a simple and lightweight text-based data format. JSON Schema is an IETF standard providing a format for what JSON data is required for a given application and how to interact with it.
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).
You can try the JSON Schema Faker. It will take a schema and generate/output a JSON object that will validate against the schema.
JSONBuddy can do this for you. It is a Windows desktop JSON editor and generates live JSON sample data while you are editing your schema.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With