JSON Formatter & TypeScript Converter

A tool for formatting JSON with 2-space, 4-space, or single-line (minify) indentation, or converting it into TypeScript interface definitions. It checks syntax in real time, and everything runs in your browser.

Your data is processed safely in your browser and never sent to a server.

How to use

  1. Paste the JSON you want to format or convert into the input area on the left.
  2. On the "Format" tab, choose 2-space, 4-space, or single-line (minify) indentation to format it in a readable way.
  3. Switch to the "TypeScript Types" tab to automatically generate a TypeScript interface definition from the structure of your JSON.
  4. If there's a syntax error, the exact line and column number and the error message are shown, so you can fix it and check again.

About this tool

This tool formats messy JSON into a readable structure, or automatically generates TypeScript type definitions from the shape of your JSON. It's handy for inspecting API responses or quickly creating type definitions for JSON data you've fetched from elsewhere.

Syntax checking uses a custom lightweight JSON parser, so error locations are always pinpointed with accurate line and column numbers, unlike the inconsistent `JSON.parse` error formats across JavaScript engines.

For TypeScript generation, objects that share the same shape within an array are merged into a single interface, and fields that are only sometimes present are automatically marked optional (`?`).

Frequently asked questions

Can I use the generated TypeScript types as-is?

Yes, the generated `interface` definition can be copied and pasted directly into your project. However, since field names and semantic meaning (like IDs) are inferred automatically, you may want to adjust the naming or types as needed.

Can it format very large JSON?

Yes, as long as your browser's memory allows it. For very large JSON, the browser may become temporarily sluggish.

Does it support JSON with an array at the top level?

Yes. When the top level is an array, type generation produces a `type` alias representing the type of the array's elements.

Is my input JSON sent to a server?

No. Syntax checking, formatting, and type generation all run in your browser's JavaScript.