How to convert JSON to a Zod schema
- Paste a representative JSON sample into the editor.
- Open the Code tab and choose Zod.
- Copy the schemas and call Root.parse(data) to validate real data.
Runtime validation, not just types
TypeScript interfaces disappear at runtime, so they cannot check what an API actually returns. A Zod schema validates the data and gives you the matching static type through z.infer, so one definition covers both compile time and runtime.
How fields are mapped
Whole numbers become z.number().int(), values that can be null get .nullable(), and keys missing from some objects get .optional(). Nested objects become their own named schemas, defined before they are used.
What is JSON?
JSON (JavaScript Object Notation) is a lightweight, text-based data format that is easy for people to read and for machines to parse. It is the de facto standard for web APIs, configuration files and data exchange between services. A JSON document is built from just six value types: objects, arrays, strings, numbers, booleans and null.
{
"name": "Ada",
"age": 36,
"admin": true,
"skills": ["math", "code"],
"address": { "city": "London" },
"manager": null
}JSON is stricter than JavaScript object literals: keys and strings must use double quotes, trailing commas are not allowed and comments are not part of the specification (RFC 8259).
Why format JSON?
APIs usually return minified JSON on a single line, which is efficient for machines but unreadable for people. Formatting (also called pretty printing or beautifying) adds consistent indentation and line breaks so that you can scan the structure, spot mistakes and review changes. Minifying does the opposite and strips whitespace to reduce size.
Frequently asked questions
Which Zod version does the output target?
The schemas use APIs that are the same in Zod 3 and Zod 4: z.object, z.array, z.union, z.number().int(), nullable and optional.
Is my JSON uploaded to a server?
No. Parsing, validation, formatting, diffing and code generation all run inside your browser, using a Web Worker. Your data is never sent to any server, which makes the tool safe for API responses, configuration files and other sensitive payloads.
Does it work offline?
Yes, after the first visit. The editor and tools are stored in your browser, so you can use them without a connection. Only the TypeScript, CSS and HTML language workers used for extra highlighting in the Code tab are downloaded the first time you use them.
How large a JSON file can I open?
Files of 20 MB and more work. Parsing happens off the main thread and the tree view is virtualized, so only the rows you can see are rendered. The editor switches to a lighter mode for very large documents.
What is the difference between formatting and minifying JSON?
Formatting (pretty printing) adds line breaks and indentation so people can read the data. Minifying removes all optional whitespace to make the payload as small as possible for network transfer or storage. Both produce identical data.
Fix common JSON errors
- Unexpected token '<' in JSON at position 0
- Unexpected end of JSON input
- Expected property name or '}' in JSON
- Trailing comma in JSON
- Expected ',' or '}' after property value in JSON
- "undefined" is not valid JSON
- Bad control character in string literal in JSON
- Unexpected non-whitespace character after JSON
- Unexpected token 'N' or an invisible character in JSON
JSON examples to try
- Simple JSON Example
- JSON Array Example
- Nested JSON Example
- User Profile JSON Example
- Paginated API Response JSON Example
- Product Catalog JSON Example
- Order and Invoice JSON Example
- Blog Posts JSON Example
- package.json Example
- GeoJSON Example
- Application Config JSON Example
- Weather API JSON Example
Cheat sheets
More JSON tools
- JSON Viewer Online
- JSON Validator
- JSON to TypeScript
- JSON to Go Struct
- JSON to Python (Pydantic)
- JSON Diff
- JSON Minifier
- JSON Pretty Print
- JSON to YAML
- JSON to CSV
- JSON to XML
- Large JSON Viewer
- JSON Tree Viewer
- JSON File Viewer
- JSON Sorter
- JSON to Rust
- JSON to Java
- JSON Schema Validator
- JSON to JSON Schema
- JSONPath Tester
- JSON Path Finder