JSON to Code

Paste a JSON sample above. Pick your language. The types come out at once, with the code that reads and writes the JSON. It runs inside your browser, so your data never reaches a server.

What it does

27 languages

TypeScript, Python, Go, Java, C#, Rust, Swift, Kotlin, Dart, C++, PHP, Ruby, Elixir, Scala, Elm, Haskell, and more. Each one in the form that language expects.

Not only types

A Zod schema, an Effect schema, PropTypes or a JSON Schema, when a check at run time is what you need. A type alone disappears when the program is built.

Every option

A struct or a class. A Pydantic model. Field tags and omitempty for Go. CodingKeys for Swift. The options belong to the language, so the row changes with it.

Two kinds of input

A JSON sample, or a JSON Schema. A schema keeps the part a sample cannot show you: what is required, and what the field means.

It stays here

No upload, no account, no log. A remote $ref in a schema fails on purpose, so nothing reaches out of the page.

Copy, download, share

Copy the code, download it with the right file name, or make a link that carries the sample. The link holds the sample after the #, which a browser never sends.

How to use it

  1. Paste a JSON response, or drop a sample in the box on the left.
  2. Choose the language at the top.
  3. Give the top type a name. Every other name follows from your keys.
  4. Turn the options on or off until the code reads the way your project writes code.
  5. Copy it, or download it as a file.

Questions

Is it free?

Yes. There is no account and no limit. Advertisements on the written pages pay for the site.

Does my JSON go to a server?

No. The generator runs inside your browser, in a worker. Nothing is uploaded and nothing is stored. You can turn off the network and the tool still works.

Which language should I pick for a check at run time?

A TypeScript interface is removed when the program is built, so it cannot catch bad data from an API. Pick Zod, or Effect Schema, or a JSON Schema, when the data comes from outside your program.

What happens to a number that is too big?

A JSON number above 9007199254740992 cannot be held by a double, which is what most JSON readers use. The code you get may lose the last digits. Keep such a value as a string, or as a decimal, and read the guide on big numbers.

Can it read a JSON Schema?

Yes. Change "The sample is" to "A JSON Schema". A reference inside the schema works. A reference to another site does not, on purpose.

How are optional fields decided?

From the sample. A key that is missing from one sample, or holds null, becomes optional. Give more than one sample, or give a JSON Schema, when the sample cannot show it.

Who writes the code?

The generator is quicktype, an open source project under the Apache License 2.0. We did not write it. The page, the options you see, the checks and the guides are ours.

Guides