Skip to content

Convert between JSON and YAML

Convert one document between JSON and YAML, in either direction, as you choose or as detected.

JSONYAMLconverttransform

Upload

Files (0–1)
One JSON or YAML document, up to 4 MB, or paste it below.
Paste a JSON or YAML document instead of uploading a file. The direction is detected automatically unless you pick one.

Options

YAML wrap width 0–4000
Questions people ask
How does the tool decide which way to convert?
If you pick a direction, that is used. In ``auto`` the tool tries JSON first (parse with the stdlib json module), then YAML (parse with ``yaml.safe_load_all``). JSON is a strict subset of YAML, so ``{"name": "toolforge"}`` parses as JSON first and is converted JSON → YAML. A document like ``name: toolforge`` does not parse as JSON and parses as YAML, and is converted YAML → JSON. A multi-document YAML stream is never inferred as JSON: that is a named refusal (``E_MULTI_DOC``). If neither parse succeeds, ``E_AMBIGUOUS``.
Is JSON → YAML really lossless?
Yes for the *values*. Every JSON type (object, array, string, number, boolean, null) has a one-to-one YAML equivalent, the parse tree round-trips, and the dumper writes the same values back in a readable layout. The number *spelling* is normalised (``1.50`` → ``1.5``); that is a format choice, not a value loss. ``lossy`` in the result metadata is only ever ``no`` for JSON → YAML.
Is YAML → JSON honest about what it cannot preserve?
Yes. YAML's safe loader maps ``2020-05-01`` to a ``date`` object and ``!!binary aGk=`` to a ``bytes`` object. Neither is JSON-native. The tool walks the tree, finds every non-JSON value, records its dotted path and type in the result metadata (`lossy: yes`, `lossy_count: N` and up to 8 `(path, type)` pairs), and converts it to its ISO-8601 / base64 string form in the output JSON. The output is still valid JSON and still carries the value; it just now lives in a string instead of in the JSON type it is not. The metadata makes that explicit and is never silently dropped. The same honesty applies to typed mapping keys (a date-stamped map becomes a map with ISO string keys, each record lossy) and to the YAML special values `.nan` and `.inf`, which become the quoted JSON names "NaN" and "Infinity"; a bare `NaN` is not JSON, so the tool never emits one. If two typed keys stringify to the same string, the first pair wins and the later duplicate is recorded as lossy right in the metadata.
What happens to a multi-document YAML stream?
Refused with ``E_MULTI_DOC``. JSON has one root value, so a stream of multiple documents has no documented, lossless mapping to JSON. You can split the stream (or name a specific document with the direction parameter) and then convert one at a time. The tool will not make a silent semantic choice for you.
Can it parse ``!!python/apply``?
No. The tool uses `yaml.safe_load_all` only, exactly like yaml-lint and yaml-format. A document with a non-safe tag is a named refusal (`E_YAML_UNSAFE`); the tag is recorded (so you can see which tag was the problem) but never instantiated.
Does anything leave my server?
No. The processor runs in an isolated container with no network access. The JSON parser is the stdlib; the YAML parser is PyYAML's ``safe_load_all``. No external resource is fetched or called.