JJSONForge
Get JSONForge

JSONForge/Guides

Generate Sample JSON from Schema Online

Learn how to instantly generate valid sample JSON payloads from existing schemas using JSONForge's client-side tools for faster testing.

October 13, 2026 · 4 min read

Generating sample JSON from a schema means creating a JSON instance that satisfies the constraints defined in your JSON Schema. You can do this manually by mapping schema properties to realistic values or automatically using a tool that interprets the schema definition. This ensures your test data matches your API contract exactly, preventing integration errors caused by mismatched types or missing fields.

Why Generate Sample JSON?

Manual creation of test payloads is often inconsistent and time-consuming. When you define a contract for your API using JSON Schema, you establish strict rules about what data is valid. Generating sample JSON from this schema guarantees that the test data adheres to these rules immediately. This is critical for backend teams who need to verify that their parsers handle edge cases correctly, such as optional fields, null values, and specific string formats.

Using a schema-driven approach eliminates guesswork. Instead of creating arbitrary JSON blobs, you create instances that reflect the actual constraints of your system. For example, if a schema requires an email address to match a specific regex pattern, the generated sample will comply with that pattern automatically. This reduces the friction between frontend consumers and backend providers, as both sides work from the same source of truth. It also helps in documenting APIs, where realistic examples are more useful than abstract placeholders.

Step-by-Step Generation Process

The process begins with a clear definition of your data structure. You start by writing a JSON Schema that describes the object’s properties, their types, and any required fields. Once the schema is finalized, you generate a JSON instance that conforms to this definition. This can be done by hand for simple objects or through automated tools for complex ones.

Consider a common scenario: defining a User object. The schema specifies that the name is a string, the email is a string with an email format, and the address is an object containing city and zip code fields. The goal is to produce a JSON payload that satisfies every constraint defined in this schema.

Here is the input schema we will use for our worked example:

{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "name": {
      "type": "string",
      "minLength": 1
    },
    "email": {
      "type": "string",
      "format": "email"
    },
    "address": {
      "type": "object",
      "properties": {
        "city": {
          "type": "string"
        },
        "zipCode": {
          "type": "string",
          "pattern": "^[0-9]{5}$"
        }
      },
      "required": ["city", "zipCode"]
    }
  },
  "required": ["name", "email"]
}

To generate the sample manually, you look at each property. The name requires a non-empty string, so "Jane Doe" fits. The email requires a valid email format, so "[email protected]" works. The address is an object where city and zipCode are required. The zipCode must match the pattern of five digits, so "90210" is a valid choice.

The resulting JSON payload is:

{
  "name": "Jane Doe",
  "email": "[email protected]",
  "address": {
    "city": "Los Angeles",
    "zipCode": "90210"
  }
}

This output satisfies all constraints. The name is present, the email is formatted correctly, and the address contains both required fields with valid values. If you were to omit the zipCode, the payload would fail validation because the schema lists it as required within the address object.

Handling Complex Nested Structures

Nested objects introduce complexity because constraints apply at multiple levels. When a property is itself an object, you must recursively apply the generation logic. Start from the deepest level and work outward, ensuring each nested object satisfies its own schema before embedding it in the parent.

Consider adding a tags array to our previous example. The schema might define tags as an array of strings, with a minimum number of items.

{
  "tags": {
    "type": "array",
    "items": {
      "type": "string"
    },
    "minItems": 1
  }
}

To generate a valid sample, you must provide an array with at least one string element. An empty array would fail the minItems constraint.

{
  "tags": ["premium", "verified"]
}

When combining this with the previous User object, the final structure looks like this:

{
  "name": "Jane Doe",
  "email": "[email protected]",
  "address": {
    "city": "Los Angeles",
    "zipCode": "90210"
  },
  "tags": ["premium", "verified"]
}

Handling unions or one-of constraints requires choosing one valid branch. If a field can be either a string or an integer, pick the type that best represents typical usage in your system. Consistency in your samples helps consumers predict behavior. Avoid generating edge cases like empty strings unless the schema explicitly allows them and they represent a realistic scenario.

Optimizing Output for Integration

Generated JSON should be concise but realistic. Avoid excessive whitespace or unnecessary fields that do not add value to the test case. The goal is to create payloads that are easy to read and debug when integration issues arise.

For API testing, focus on covering the happy path first. Ensure all required fields are present and correctly typed. Then, create additional samples for optional fields to verify that your API handles missing data gracefully. For instance, if address is optional in the schema, create one sample with the address object and another without it.

When using tools to generate these samples, look for features that allow you to inspect and validate the output immediately. JSONForge lets you paste a JSON payload and generate a clean JSON Schema from it, which helps you verify that your structure matches your intended contract. This saves time compared to manually formatting the JSON after generation.

Troubleshooting Common Issues

Validation failures often stem from subtle mismatches between the schema and the generated data. The most common issue is ignoring the required array. Even if a field has a default value in your application logic, the schema might require it to be explicitly present in the JSON payload. Always check the required list for each object level.

Another frequent problem is type mismatch. JSON distinguishes between numbers and strings carefully. If a schema specifies "type": "number", the value 42 is correct, but "42" is not. Ensure your generated values match the declared types exactly. Boolean values should be true or false, not "true" or "false".

Null handling is also tricky. If a field is nullable, the schema might allow null. However, some validators treat missing fields differently from null values. If the schema does not explicitly allow null, omitting the field might be safer than setting it to null, depending on your backend’s parsing logic. Test both scenarios if your system is sensitive to these distinctions.

Finally, check for pattern constraints. Regex patterns like ^[0-9]{5}$ are strict. Ensure your generated values match the pattern exactly, including case sensitivity if specified. A quick validation step after generation catches these errors before they reach your production environment.

Do it in JSONForge

Everything in this guide works in the browser — open the tool and try it on your own input.

Open JSONForge →

Questions people also ask

Does JSONForge support JSON Schema draft 2020-12?

Yes, JSONForge supports JSON Schema draft 2020-12. This ensures compatibility with the latest standard features and validation rules for modern API contracts.

Is my data sent to a server during generation?

Yes, your schema and generated data are processed on the server to ensure accurate validation and formatting. This central processing guarantees that the output strictly adheres to the defined constraints without local environment discrepancies.

Can I customize the generated sample values?

Yes, you can customize generated values by defining specific examples or defaults directly within your JSON Schema properties. This allows you to control the exact content of the output while maintaining structural validity.

More guides