JSON · Converters

JSON → TypeScript

Paste any JSON payload and get clean, ready-to-use TypeScript interfaces. Runs entirely in your browser, nothing is uploaded.

JSON in
TypeScript out

What is JSON?

JSON (JavaScript Object Notation) is a lightweight, text-based format for representing structured data. It was derived from JavaScript object syntax but is language-independent: every major language can read and write it. Its job is to move structured data between systems, API responses, config files, message payloads, in a form that is both human-readable and trivially machine-parseable. That combination is why it became the default data format of the modern web.

JSON data types

JSON allows exactly six value types, no more:

  • string (double-quoted), number, boolean (true/false), and null.
  • array (an ordered list in [ ]) and object (key/value pairs in { }, keys must be strings).

Notably absent: dates (use ISO 8601 strings), comments, trailing commas, undefined, and functions. Those are the source of most “why won’t my JSON parse” bugs (see common mistakes).

JSON in code

Every language has a parse step (text to value) and a serialize step (value to text). JavaScript:

// parse a JSON string into an object
const obj = JSON.parse('{"id":42,"name":"Flat White"}');

// serialize an object back to JSON (the 2 is the pretty-print indent)
const text = JSON.stringify(obj, null, 2);

Python:

import json

# parse a JSON string into a dict
data = json.loads('{"id": 42, "name": "Flat White"}')

# serialize a dict back to JSON
text = json.dumps(data, indent=2)

Want types for that data? That is exactly what the tool above does, paste the JSON and get TypeScript interfaces.

JSON in AI

JSON quietly became the language AI systems speak to the rest of your code. It did not exist as a concern when most JSON tutorials were written, but in 2026 it is everywhere a model meets software:

  • Structured outputs: models return JSON that matches a schema you define, so the result drops straight into your program. See structured outputs and build one with the Structured Output Builder.
  • Tool / function calling: when a model calls a tool, its arguments come back as JSON, see tool calling.
  • MCP: the Model Context Protocol is built on JSON-RPC.
  • API responses: the data you feed a model, and get back, is almost always JSON.

JSON vs XML

JSONXML
ShapeKey/value + arraysNested tags + attributes
VerbosityCompactHeavier (closing tags)
Typesstring, number, bool, null, array, objectText only (everything is a string)
CommentsNot allowedAllowed
Best forAPIs, configs, JS-native dataDocuments, mixed content, feeds (RSS/Atom)

Common mistakes

  • Trailing commas. Valid in JavaScript, invalid in JSON. [1, 2,] will not parse.
  • Single quotes. JSON strings and keys must use double quotes.
  • Comments. Not allowed in standard JSON; strip them first.
  • Unquoted keys. { name: "x" } is a JS object, not JSON; keys must be quoted.
  • Wrong types for dates / big numbers. Use strings; very large integers can lose precision as JSON numbers.

About this tool

Paste a JSON object or array on the left and KB Cafe walks the structure to produce matching interface declarations on the right, entirely in your browser. The inference rules:

  • Objects become an interface; nested objects get a named child interface from the key.
  • Arrays are typed by merging every element, [1, 2] is number[], and an array of objects merges their keys (missing keys become optional).
  • null values widen a field to … | null rather than guessing.
  • Empty arrays / objects fall back to unknown[] and Record<string, unknown> so nothing is silently wrong.

FAQ

Is my JSON sent to a server?

No. The converter is plain JavaScript that runs on this page. Your input never leaves your browser, which is why it works offline once the page has loaded, safe for API responses or config you would rather not upload.

What is the difference between JSON and a JavaScript object?

JSON is a text format whose syntax is a strict subset of JavaScript object literals. In JSON, keys must be double-quoted strings, only six value types are allowed, and there are no comments, trailing commas, or functions. A JS object is a live in-memory value; JSON is its serialized text form.

Can JSON have comments?

No, standard JSON does not allow comments. If you need them in a config file, use a superset like JSONC or JSON5, or keep comments in a separate field, but strip them before any strict JSON parser sees the file.

Does JSON have a date type?

No. JSON has no date type, dates are conventionally written as ISO 8601 strings ("2026-06-19T12:00:00Z") and parsed back by your code. The same goes for big integers and binary data, which are usually strings (often Base64).

Why are some generated fields marked optional with ?

When an array contains objects that do not all share the same keys, the keys missing from some elements are marked optional. You can also force every field optional with the toggle above.

JSON vs XML, which should I use?

JSON for APIs, configs, and anything JavaScript-native, it is compact and parses natively everywhere. XML for documents, mixed content, and feeds (RSS and Atom are XML). XML supports comments, attributes, and namespaces that JSON deliberately omits.

Does it handle deeply nested JSON?

Yes, nesting is unlimited. Each distinct object shape becomes its own interface, named after the key that holds it.

Related

JSON → Go · CSV → JSON · YAML → JSON · JWT decoder (Base64URL JSON) · Base64 · HTTP · Structured Output Builder.