JSON Converter
Convert JSON to YAML, CSV or TypeScript types, and YAML back to JSON.
What is the JSON Converter (YAML · CSV · TypeScript)?
The JSON converter turns JSON into other formats, or other formats into JSON. It offers four modes: two-way JSON ↔ YAML conversion, converting an array of objects into tabular CSV, and automatically generating TypeScript types (interfaces) from a JSON structure. It's handy for switching config file formats, exporting data, and drafting type definitions.
The TypeScript conversion doesn't just produce a top-level type: it extracts nested objects into separate interfaces, and for arrays of objects it merges the keys of all elements into one interface, marking keys present in only some elements as optional (?). The CSV conversion uses the union of all rows' keys as the header, and places nested object or array values into cells as JSON strings.
YAML parsing and generation use the well-tested yaml library, and every conversion runs entirely inside your browser. The data you enter is never sent to a server, so it's safe to paste real config files or data.
How to use
- Pick a conversion direction from the tabs at the top: JSON → YAML, YAML → JSON, JSON → CSV, or JSON → TS types.
- Paste input matching the chosen direction. JSON → CSV requires an array of objects ([{...}, {...}]).
- Click 'Convert' to see the result. Use the copy button to grab it; if conversion fails, an error message explains the cause.
Frequently asked questions
- What kind of data does JSON → CSV expect?
- It needs a non-empty array of objects, for example [{"id":1,"name":"kim"},{"id":2,"name":"lee"}]. If it isn't an array, or an element isn't an object, you get an error. Each object's keys become the CSV headers (columns).
- What happens to nested objects and arrays when converting to CSV?
- CSV is a flat, tabular format that can't hold nested values directly. So nested object or array values are serialized as JSON strings into the cell. Values containing commas, double quotes, or line breaks are automatically quoted according to CSV rules.
- How accurate is the generated TypeScript type?
- Types are inferred from the JSON sample you provide. Nested objects become separate interfaces, and arrays of objects merge their elements' keys, marking keys present in only some elements as optional (?). Note that empty arrays become unknown[] and null values become the null type, so you may want to refine the output to match your real schema.
- Anything to watch out for in YAML ↔ JSON conversion?
- YAML supports features like comments and anchors, but converting to JSON discards that information. YAML also expresses structure through indentation, so misaligned indentation causes a parse error. The conversion preserves values and structure, and if the syntax is wrong, an error message explains why.