JSON to Code Generator
Paste a sample JSON object or array, pick a language and name the root type. The tool reads the keys and values, merges the items of an array, and marks fields that are missing or null in some items as optional. Check the generated types against your real data before you rely on them.
JSON to Code Generator runs entirely in your browser: the text you paste is never sent to a server. It is free and needs no sign-up.
How to use it
- Paste a sample JSON Paste a sample JSON object, or an array of objects, into the JSON example box. Choose a language, then name the root type using only letters, digits and underscores, without starting with a digit.
- Read the optional fields A field that is missing or null in some items is marked optional: TypeScript adds a question mark, and other languages use their own optional or nullable form. Objects inside an array are merged into one type.
- Copy the generated code Press Copy to put the code on the clipboard. Go, Java, C# and Rust follow their usual naming habits, and a renamed field keeps its original JSON key in a tag, an annotation or a comment.
Questions
How are field names chosen for each language?
TypeScript keeps the JSON key. Go uses PascalCase and keeps common initialisms such as ID. Python and Rust use snake_case, Java uses camelCase and C# uses PascalCase. A name that is a reserved word gets a trailing underscore.
What happens when the root is an array?
The item type is generated from the objects in the array, and a comment above it says the root is an array. The objects are merged, so a field present in only some of them becomes optional. A root that is neither an object nor an array of objects is refused with a message.
How do plural names turn into type names?
The tool uses a rough rule: items becomes Item and categories becomes Category, so an array named in the plural gets a singular type name. Irregular words can come out wrong, so rename the type after copying if needed.