Check a converted JSON-to-Zod result by reviewing the inferred source, compiling it with your intended Zod version, and testing accepted and rejected fixtures against the authoritative data contract.

The JSON to Zod Schema Converter generates a reviewable candidate from one valid object, array, or primitive JSON value. It processes the sample locally and emits plain source text containing an import, a schema declaration, and an inferred TypeScript type. It does not upload the sample, load Zod, or execute the generated code, so a successful conversion is not the same as a successful contract check.

how do i check the result after i convert json to zod schema
How to Check a JSON to Zod Schema Result

Separate sample inference from the real contract

A generated schema describes what appeared in its input sample. It cannot establish every field that may appear in production. A field present in one example may still be optional, while a field absent from the sample may still be valid. The required and optional decisions are therefore review points, not final contract guarantees.

For example, when an array contains objects, the converter merges their keys. A property observed in every sampled object becomes required, while a property missing from at least one sampled object becomes optional. Values found under the same key are merged recursively. This is useful evidence about the sample, but broader production states must come from API documentation or other representative fixtures.

A useful review separates three questions: Does the source compile? Does its inferred shape match the documented contract? Does it accept and reject the expected production cases? Reviewing only the field names cannot answer the last two questions. For a deeper explanation of this distinction, see Does a Generated Zod Schema Prove Your API Contract?.

Read every inferred part of the source

Review the generated source line by line, focusing on choices that can make the schema broader or narrower than the intended data contract.

Observed JSON Generated Zod shape Review point
String z.string() Check whether the contract requires a format, pattern, or other string rule.
Finite JSON number z.number() Check whether it must be an integer or fall within documented limits.
Boolean z.boolean() Confirm that only true and false are valid values.
Null z.null() Confirm that null is meaningful by itself.
Object z.object({...}) Review every required and optional property against the contract.
Array with one observed element shape z.array(element schema) Check that every element in the contract has that same shape.
Array with mixed element shapes z.union([...]) Confirm that every union member is allowed and no allowed type is missing.
Null combined with another observed type A nullable form of that schema Verify that null can occur with the other type.
Empty array z.array(z.unknown()) Recognize that the converter could not determine an element type.

Nested arrays and objects are handled recursively. Object properties retain their source encounter order. Keys containing spaces, hyphens, numeric starts, quotes, or other unsafe JavaScript names are emitted with JSON string escaping so the generated source remains valid. Mixed values use deterministic union ordering, and identical union members are deduplicated, which makes repeated conversion of the same JSON stable.

The inferred TypeScript type reflects the same sampled shape. It does not reveal formats, business rules, or future fields that the sample never exposed.

Run a contract-level verification workflow

  1. Confirm the generation inputs. Use one valid, representative JSON value and a valid JavaScript identifier for the exported schema. If the source already exists, verify that its identifier and underlying sample still correspond to the contract you intend to enforce.
  2. Generate and inspect the source. Review every object property, array, union, numeric mapping, nullable value, and empty-array choice. Pay particular attention to fields that appeared in only one sampled object.
  3. Copy the source into the destination project. Install the intended Zod version there and pin that version so validation behavior does not change unexpectedly. The converter itself emits source text and does not install or run Zod.
  4. Format and compile the result. Run the project’s formatter and TypeScript compiler or type checker. Resolve import, export, identifier, and inferred-type errors before relying on runtime tests.
  5. Run positive and negative validation tests. Use the Zod validation API in your project, such as safeParse, to assert that accepted fixtures succeed and rejected fixtures fail. Consult the Zod API documentation for the validation method and result shape supported by your pinned version.
  6. Add contract-only rules and repeat the checks. The generator does not infer string formats, minimums, maximums, integer constraints, enums, literals, discriminated unions, dates, UUIDs, URLs, email addresses, brands, coercions, defaults, transformations, refinements, records, tuples, strict-object behavior, recursive references, or business rules. Add only rules supported by the authoritative contract, then format, compile, and test again.

Design fixtures that challenge the inferred schema

Define expected results from the authoritative contract before running the generated schema. Otherwise, a test can accidentally confirm the sample instead of the real requirements.

  • Optionality: Include an accepted payload that omits a field present in the sample. If the contract allows that omission, a generated required field will expose an incorrect inference.
  • Nullability: Test both null and non-null values wherever the contract permits them. A nullable result should be justified by documented behavior, not merely by one unusual sample.
  • Union members: Send each allowed element type through a mixed array. The deterministic union should include those types without admitting a type the contract forbids.
  • Empty arrays: Include an empty array when the API can return one. Because the converter uses z.array(z.unknown()), the resulting schema will not enforce an element shape that the sample could not reveal.
  • Formats and ranges: Cover documented identifiers, dates, URLs, email addresses, integer fields, and numeric boundaries. Generic primitive schemas do not enforce those constraints.
  • Unknown properties: Test extra fields according to the project’s documented object behavior. The converter does not infer strict-object handling, so this expectation needs an authoritative basis.

Use representative fixtures for different real states, such as populated and empty collections, nullable and non-nullable records, and alternative object shapes. Keep independent payload contracts separate rather than combining unrelated payloads into one inferred schema.

Handle strict input and conversion boundaries

The converter parses strict JSON before inference. JavaScript comments, trailing commas, NaN, Infinity, undefined, BigInt syntax, single-quoted strings, and object literals are rejected rather than silently repaired. If conversion reports invalid JSON, correct the input before drawing conclusions about the resulting schema.

JSON numbers have already passed through JSON.parse and therefore follow JavaScript number precision. Identifiers and currency amounts that require exact decimal semantics should usually remain strings unless the authoritative contract defines another representation.

Work is bounded at 500,000 input characters, 50,000 visited values, 40 nesting levels, and 1,000,000 generated characters. Reaching a limit returns an explicit error and never emits a partial schema. Deep or very wide inputs can still be poor contract documentation even when they remain under those limits, so prefer a small representative fixture and split independent payloads into separate schemas.

Use a final sign-off checklist

Before treating the schema as production-ready, confirm each of these points:

  • The source was generated from valid JSON and reviewed against authoritative documentation, not only against the sample.
  • Required fields, optional fields, nullable values, unions, numbers, and empty arrays have each been checked.
  • Any added format, range, enum, transformation, refinement, or business rule comes from the authoritative contract.
  • The intended Zod version is pinned, and the copied source has been formatted and compiled successfully.
  • Accepted fixtures pass, rejected fixtures fail, and representative production states are covered.
  • Independent payload shapes have separate schemas, and no partial output from a limit error is being used.

A passing sample is only one signal. The final result comes from source review, successful compilation, runtime validation against expected cases, and alignment with the authoritative contract.

For a deeper look, see How to Validate JSON Response in REST Assured.