JSON ⇄ YAML Converter

Convert between JSON and YAML formats

About this tool

JSON and YAML describe the same data in different syntax. JSON is strict, terse and machine-first, which is why APIs speak it; YAML uses indentation and supports comments, which is why Kubernetes, Docker Compose, Ansible and CI systems are configured with it.

This converter moves a document between the two in either direction. It parses the input properly, so a JSON syntax error is reported as an error instead of producing a silently truncated file.

When to use it

  • Turning a Kubernetes or Docker Compose manifest into JSON for a tool that only accepts JSON
  • Converting an API response into YAML to paste into a config file
  • Checking that a YAML document actually parses before you deploy it
  • Producing readable, indented JSON from a minified API payload

Worked example

Input

{
  "name": "John Doe",
  "age": 30,
  "hobbies": ["reading", "coding"]
}

Output

name: John Doe
age: 30
hobbies:
  - reading
  - coding

The converter indents with two spaces. Conversion is lossless for the data types JSON and YAML share, with a few named exceptions — see the FAQ below.

Frequently asked questions

Is the conversion lossless?

For the data types the two formats share, yes, and the converter tells you when it isn't: YAML comments and anchors are dropped silently (JSON has no equivalent), while non-finite numbers (.inf, -.inf, .nan), binary values (!!binary) and non-string or complex mapping keys are converted to their closest JSON representation and called out in a note above the output.

Why do JSON numbers change when I convert to YAML?

Very large integers can lose precision when a parser treats them as floating point. The converter dumps YAML with reference expansion disabled and a wide line width, but it cannot exceed the precision of the underlying JSON parser.

Does this tool send my document anywhere?

No. Both the JSON and YAML parsers run entirely in your browser, so configuration files with secrets in them never leave your machine.

What happens with a `---`-separated file, like a Kubernetes manifest?

YAML to JSON reads every document in the stream. One document converts to a JSON object as before; two or more convert to a JSON array of the documents in source order, with a note above the output saying how many were found. An empty document between two real ones (two `---` in a row) becomes `null` in that array position, so the positions still line up with the source.

Related tools