JSON Converter

Converter & Viewer

Tree View.json
WorkspaceReady
Chars: 0Lines: 0

Session History

No history yet...

JSON Formatter, Validator and Multi-Language Converter

Format, validate and convert JSON to TypeScript, Go, Rust, Kotlin, Python, C#, GraphQL, YAML, TOML and more. Live tree view, diff tool, path filter, and smart fix. Free, instant, private.

A Sample Is a Snapshot, Not a Contract

This tool converts one JSON document into typed models across eighteen output formats: TypeScript, Zod, Go, Rust, Kotlin, Python, C#, Java, GraphQL, JSON Schema draft-07, YAML, TOML, PHP, XML, CSV, SQL, plus a tree view and a diff view. Every generator infers types from a single sample, which is one observation of a shape, not a guarantee of it. This document covers where that distinction matters: how each generator maps types, where inference has nothing to work with, and what to adjust before the output enters a codebase.

Each generator walks your document, checks values with typeof, and emits a type for what it saw. Arrays are typed from their first element only, and every key that appears becomes a required field. That is honest about one document, but real APIs are messier: a field present in your sample may be absent in production, an array's first element may not represent the rest, and a date-shaped string stays a string because the generator saw a string.

Read the output as a scaffold. The tool writes the mechanical bulk in seconds: field names, nesting, casing conversions, struct tags. The judgment calls, optionality, unions, date types, large integers, stay yours.

Absent Keys and Null Values Are Two Different Absences

JSON has two ways to say "no value," and they mean different things. An absent key means the sender omitted the field. A key present with null means the sender included the field and marked it empty. The generators handle both unevenly.

With "coupon": null, as in the built-in e-commerce sample, TypeScript emits coupon: null, a type that accepts only null. Go emits interface{}, Rust emits Option<serde_json::Value>, Kotlin emits Any?, Python emits Optional[Any]. None of these say "string or null," because the sample never showed a string. If the real API sends a coupon string usually and null otherwise, every generated type compiles and fails at runtime.

The absent key is harder: if the sample never includes the field, no generator can know it exists. TypeScript marks every observed field required, the schema lists every key in required, and Go emits plain fields with no omitempty. The fix is manual: add ? in TypeScript, drop the field from required, or wrap in Optional/Option/Any? in Python, Rust, and Kotlin. For each field that looks always-present, check whether the API documentation promises that or your sample just happened to include it.

Empty Arrays Carry No Type Information

An empty array is a type with no evidence. In the built-in product catalog sample, one product has "variants": [], and the generators answer with their honest fallback for "array of unknown": TypeScript emits any[], Go emits []interface{}, Rust emits Vec<serde_json::Value>, Kotlin emits List<Any>, Python emits List[Any], GraphQL emits [JSON], Zod emits z.array(z.unknown()), and the schema generator emits items: {} with no constraints.

These fallbacks compile, but they are placeholders. Paste a second sample with a populated array before finalizing, or write the element type by hand. Replace any[] with the real element interface in TypeScript, []interface{} with the concrete slice type in Go, and Vec<serde_json::Value> with Vec<Variant> in Rust. The generator did the best possible thing with no data; the moment you have data, replace the placeholder.

Date-Looking Strings Are Still Strings

APIs transmit dates, UUIDs, emails, and URLs as JSON strings, because JSON has no native date type. A converter that promoted every ISO-8601-looking string to a date type would be guessing, so the generators do not guess. Go emits string, Rust emits String, Python emits str, TypeScript emits string. No generator produces time.Time, chrono::DateTime, or datetime.datetime.

The one exception is Zod, which appends refinements after pattern-matching values: .datetime(), .uuid(), .email(), .url(). Those validate at runtime but remain string schemas, not date objects. If you need date arithmetic, convert explicitly where data enters your code and keep the generated string at the serialization layer.

Integers Larger Than 2^53 Do Not Survive the Browser

JSON has a single number type, and JavaScript parses every JSON number into an IEEE-754 double. Any integer above 2^53 - 1, about 9.007 quadrillion, cannot be represented exactly after JSON.parse runs. Snowflake-style IDs from systems like X or Discord live above that line. A value like 9223372036854775807 arrives in the browser already rounded, before any generator sees it.

The mappings reflect each language's idioms, not the original precision. TypeScript emits number for everything, Go emits int and float64, Rust emits i64 and f64, C# emits int and double, Java emits double, Python emits float, Kotlin emits Int and Double, GraphQL emits Int and Float. Note the trap: Rust's i64 could hold the value, but it receives an already-rounded value from the parser, so the correct struct type still carries the wrong number. The fix is at the source: APIs exposing 64-bit IDs should transmit them as strings, which the generator types as string everywhere and which survive parsing exactly.

Reading the draft-07 Schema the Tool Generates

The Schema tab emits JSON Schema with the draft-07 $schema declaration, a type for every value, properties for nested objects, a required array of every observed key, and an items schema inferred from each array's first element. That is a valid starting contract for validation with Ajv, documentation in OpenAPI tooling, or editor support in VS Code, which offers autocomplete and inline errors for JSON files that declare their schema.

A generated schema describes one document; a production schema describes all of them. Close the gap with keywords the generator cannot infer. additionalProperties: false locks an object against unexpected keys. format constrains strings without changing their type: "format": "date-time", "format": "email", "format": "uri". enum restricts a field to a fixed set, useful for status fields the sample shows once. anyOf and oneOf express the unions the sample could not show, such as "type": ["string", "null"] for the nullable coupon field above. The generated schema is the scaffold; these keywords are the contract.

Diffing Documents by Structure Instead of Text

The Diff tab compares two JSON documents at the top level: keys only in the second document get +, keys missing from it get -, and keys present in both with different values get ~, compared via serialized JSON. That is enough to spot a renamed field between API versions, confirm a migration produced the expected additions, or verify that two payloads which should be identical actually are.

Structural diffing goes deeper: it recurses into nested objects and arrays and reports each change as a path-addressed operation. The standard vocabulary is RFC 6902 JSON Patch, add, remove, replace, move, copy, and test, each addressed by a JSON Pointer path like /items/0/price. Arrays are the hard part: an insertion at index 0 shifts every later index, so naive diffs report noise. Serious implementations detect moves, compare elements by identity keys rather than position, or offer order-insensitive comparison, and they handle equivalences text comparison misses, like 1 versus 1.0 or key ordering.

For day-to-day work, narrow before comparing: use the path filter to extract the subtree you care about, such as data.orders, from each document, then diff the extracted subtrees. Small comparisons produce readable change lists; whole-document diffs of large payloads produce noise. For the TypeScript side, including optional fields, unions, and utility types, see JSON to TypeScript: Convert API Responses to Types.

Frequently Asked Questions

The generator saw each key exactly once, in a document where it was present, so it emits a required field. Presence in one sample says nothing about the next response. Check the API documentation for each field's optionality and add `?` to the ones that can be absent. If you have several sample responses, convert the one with the most fields first, then mark optional the fields missing from the others.
Yes, and the distinction lives in two different keywords. A field that can be null but is always present keeps its place in `required` and gets a union type like `"type": ["string", "null"]`. A field that can be absent is removed from `required` while keeping its normal type. The generator cannot tell which case applies from one sample, so it produces neither; add them by hand from the API contract.
Not reliably. The browser parses the JSON before generation, and any integer above 2^53 - 1 is already rounded by `JSON.parse`, so even Rust's `i64`, which could hold the value, receives a corrupted one. The types compile and silently carry the wrong ID. Ask the API provider to send large IDs as strings, which the generator types as `string` everywhere and which survive parsing exactly.
Feed the schema and a batch of real responses to Ajv and iterate on the failures. Each failure names the path and the violated keyword, telling you exactly which constraint to add or loosen. Pay special attention to `additionalProperties`, which the generator leaves open: set it to `false` on objects you want locked, then watch for legitimate new fields the API adds over time.

One Tool for the Entire JSON Workflow

The fragmented approach to JSON tooling has a real cost. One site to format, another to convert to TypeScript, a CLI for Rust structs, a separate tool for YAML, something else for JSON Schema. Switching between them and re-pasting data wastes time that compounds across a working week.

This tool keeps the entire workflow in one place. Format, validate, explore, filter, compare, and convert to any format your project requires. Everything runs locally in your browser with no latency, no account, and no data leaving your machine.

For formats where dedicated tooling is sparse, including Rust Serde structs, TOML conversion, GraphQL schema generation, and JSON path filtering, this covers what most developers have been handling with manual work or command-line scripts. All of it free.

In-depth guide

JSON to TypeScript: Convert API Responses to Types

Learn nested objects, arrays, optional fields, unions, and utility types with copy-paste examples.

Read the guide