Synthetic Data Generator for JSON Schema: Build Realistic Datasets From Any Schema
JSON Schema is one of the most widely-used schema definition formats in modern software development. If your data has a JSON Schema, you have everything you need to generate realistic synthetic datasets — but naive schema-based generation produces garbage. This guide shows you how to do it properly.
Why JSON Schema Is an Excellent Starting Point for Synthetic Data
JSON Schema provides three things that synthetic data generators need: type information (string, number, integer, boolean, array, object), constraints (minimum, maximum, pattern, enum, required, format), and structural relationships (nested objects, arrays of objects, references via $ref). A well-defined JSON Schema is more than documentation — it is a machine-readable specification of the data domain that a generator can use to produce schema-valid synthetic records.
The challenge is that schema-valid does not mean realistic. A generator that produces random strings conforming to a regex pattern, random numbers within bounds, and random booleans will produce schema-valid data that is statistically nonsensical — names that look like "XvK93pQ", ages randomly distributed from 0 to 150, email addresses that match the format but share no realistic distribution with real email addresses. Schema-valid garbage is useless for testing application behavior and completely useless for ML training.
The goal is schema-constrained realistic generation: data that satisfies every constraint in the schema while having realistic statistical properties — realistic names, realistic email domains, realistic age distributions, realistic correlations between fields.
Anatomy of a JSON Schema Synthetic Data Generator
Step 1: Schema Parsing and Type Analysis
The first step is parsing the JSON Schema to identify the type hierarchy, constraints, and required fields. For each property, the generator needs to determine:
- The JSON type (
string,number,integer,boolean,array,object) - Any format specifiers (
date-time,email,uri,uuid,ipv4) - Numeric constraints (
minimum,maximum,exclusiveMinimum,multipleOf) - String constraints (
minLength,maxLength,pattern,enum) - Array constraints (
minItems,maxItems,uniqueItems,itemsschema) - Whether the field is in the
requiredarray
Step 2: Semantic Field Detection
This is the step that separates realistic generation from schema-valid garbage. Semantic field detection uses the field name, description, and format to determine what kind of real-world value the field represents — and then generates from the appropriate realistic distribution rather than a random distribution.
A field named firstName or first_name should generate realistic first names from a locale-appropriate frequency distribution, not random strings. A field named email with format email should generate realistic email addresses with realistic domain distributions. A field named age with minimum 18 and maximum 120 should generate ages with a realistic age distribution, not a uniform distribution from 18 to 120.
Libraries like Faker (Python, JavaScript, PHP, Ruby) provide semantic value generation for hundreds of common field types. The key is mapping your schema fields to the appropriate Faker providers using field name heuristics and format specifiers.
Step 3: Cross-Field Correlation and Conditional Logic
Real data has correlations between fields. Age and retirement status are correlated. Country and currency are correlated. Job title and salary are correlated. A naive generator treating each field independently will produce data where a 22-year-old is listed as a retired CEO earning $0 — technically valid, statistically absurd.
JSON Schema supports if/then/else and dependentSchemas for expressing conditional constraints — a generator must respect these. For correlations not expressed in the schema (because JSON Schema doesn't support them), you have two options: encode them as generation rules in your generator configuration, or use a statistical model trained on reference data to learn and reproduce correlations.
Step 4: Referential Integrity for Nested Schemas
JSON Schema's $ref mechanism allows schemas to reference other schemas. When generating from schemas with $ref, your generator must resolve references and maintain consistency — if a userId appears in both a user object and an order object, both instances should reference the same set of generated user IDs.
Practical Implementation: Tool Choices
json-schema-faker (JavaScript/TypeScript)
json-schema-faker is the most widely-used JavaScript library for generating synthetic data from JSON Schema. It integrates with Faker.js and Chance.js for realistic value generation and supports the full JSON Schema Draft 7 specification. Configuration is done via x-faker and x-chance extension properties in your schema, which tell the generator which Faker or Chance provider to use for a given field.
Example configuration for a user object schema:
{
"type": "object",
"properties": {
"id": { "type": "string", "format": "uuid" },
"firstName": {
"type": "string",
"x-faker": "person.firstName"
},
"email": {
"type": "string",
"format": "email",
"x-faker": "internet.email"
},
"age": {
"type": "integer",
"minimum": 18,
"maximum": 80,
"x-faker": { "datatype.number": [{"min": 18, "max": 80}] }
}
},
"required": ["id", "firstName", "email", "age"]
}Hypothesis (Python)
The Hypothesis library, primarily a property-based testing tool, includes a JSON Schema strategy via the hypothesis-jsonschema package. It generates schema-valid examples for property-based testing — useful for API testing and contract validation, though less focused on realistic value distributions.
LLM-Based Generation for Complex Schemas
For schemas with complex semantic relationships that are difficult to encode in generation rules, LLMs (GPT-4o, Claude) can generate realistic synthetic records when given the schema and a description of the domain. The approach is to prompt the model with the schema and ask for N realistic records as a JSON array. This works well for schemas with rich semantic content (e.g., customer support ticket schemas, medical record schemas) where semantic realism matters more than statistical precision. For high-volume generation, cache schema-level prompts and batch generation requests.
Validating Generated Synthetic Data Against the Schema
Always validate generated records against the original schema. Use a compliant JSON Schema validator (ajv in JavaScript, jsonschema in Python) to confirm that every generated record passes validation. Validation failures reveal generator bugs — handle them by fixing the generator, not by filtering out invalid records. A generator that produces invalid records 0.1% of the time will corrupt ML training pipelines at scale.
Common Pitfalls to Avoid
- Ignoring optional fields — Optional fields (not in
required) should sometimes be absent and sometimes present, with realistic absence rates. Generating optional fields in 100% of records is unrealistic. - Uniform distributions everywhere — Real-world values are almost never uniformly distributed. Ages, transaction amounts, text lengths, and most other business values follow skewed distributions. Hard-code realistic distributions or learn them from reference data.
- Ignoring null types — JSON Schema's nullable types (
type: ["string", "null"]) should generate null values at realistic rates, not always non-null values. - Not testing referential integrity at scale — ID consistency across related records breaks in subtle ways at high generation volumes. Test explicitly with 10K+ record batches.
For broader context on synthetic data generation techniques beyond JSON Schema, including GAN-based and statistical methods, our article on synthetic data generation techniques covers the full landscape.
AllSynthetica supports schema-driven synthetic data generation with built-in semantic field detection, referential integrity handling, and statistical realism. Contact us to see how it works with your JSON Schema definitions.

