JSON Sample From Schema
JSON Sample From Schema is a simple plugin for VSCode that allows you to generate single or multiple sample JSON files from a valid JSON Schema.
Features
Generate sample JSON files, with random data, from a single JSON Schema.
Strings will have random characters, numbers will have random values, regular expression values will have random valid values etc.
Powered by JSON Schema Faker with support for Faker and Chance.
Using This Extension
CTRL+SHIFT+P
to open the command pallet.
- Run the command
Generate JSON Sample from Schema
Convert your JSON Schema, for example:
{
"$id": "https://example.com/blog-post.schema.json",
"$schema": "https://json-schema.org/draft/2020-12/schema",
"description": "A representation of a blog post",
"type": "object",
"required": ["title", "content", "author", "publishedDate"],
"properties": {
"title": {
"type": "string"
},
"content": {
"type": "string",
"example": "Some content goes here..."
},
"author":{
"type": "string",
"faker": "person.fullName"
},
"publishedDate": {
"type": "string",
"format": "date-time",
"faker":
{
"date.recent":{
"days": 10
}
}
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
to the following:
{
"title": "Lorum ipsum officia ex",
"content": "Some content goes here...",
"author": "Joe Blogs",
"publishedDate": "2024-03-25T00:00:00.0Z",
"tags": [
"aute consequat commodo exercitation",
"exercitation velit",
"id",
"nisi",
"sint culpa non"
]
}
Settings
Navigate to File
→ Preferences
→ Settings
.
Then under Extensions
→ JSON Sample From Schema
the following values can be set:
Note: some settings are options for JSON Schema Faker.
Setting |
Description |
Default Number Of Samples |
The default number of samples to generate. Change to a specific number which is more convenient for your workflow. |
Max Number Of Samples |
The maximum number of samples that can be generated to stop very high numbers being entered by accident. |
Use Examples Value |
JSON Schema Faker - Use 'example' or 'examples' fields from the JSON Schema in the generated samples. |
Required Only |
JSON Schema Faker - Only add 'required' fields to the generated sample JSON. |
Always Fake Optionals |
JSON Schema Faker - When enabled, it will set optionalsProbability: 1.0 and fixedProbabilities: true . Note that this property is overridden by 'Required Only' above. |
Enable Custom Json Schema Faker Configuration |
JSON Schema Faker - If enabled, the 'Custom Json Schema Faker Configuration' below will be used. Otherwise it will be ignored. Note that if the custom configuration is used then the above 'JSON Schema Faker' settings will be ignored. |
Custom Json Schema Faker Configuration |
JSON Schema Faker - Custom Configuration based on JSON Schema Faker custom options available here: https://github.com/json-schema-faker/json-schema-faker/tree/master/docs#available-options. To use, ensure that 'Enable Custom Json Schema Faker Configuration' above is checked. All other 'JSON Schema Faker' settings will be ignored. |