Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate sample Json output from Json Schema

Tags:

java

json

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 ?

like image 258
Abhijeet Kushe Avatar asked Feb 19 '14 23:02

Abhijeet Kushe


People also ask

What is $id in JSON Schema?

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" }

Is JSON Schema 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.

What is JSON format output?

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).


2 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.

like image 99
Eric Olson Avatar answered Oct 02 '22 17:10

Eric Olson


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.

like image 7
Clemens Avatar answered Oct 02 '22 16:10

Clemens