How to Convert JSON to YAML: A Config Guide

Last updated: · 3 min read

When you need to move data from a JSON API response into a Kubernetes, Docker Compose or CI configuration, you often have to write the same data as YAML. YAML builds structure with indentation instead of braces and quotes, which many people find easier to read and review. The JSON to YAML Converter parses your JSON and writes it back as YAML with two-space indentation, using the js-yaml library. The data stays the same; only the notation changes. The conversion runs in your browser.

Formula

1. Parse the text with JSON.parse; if the JSON is invalid, stop and report the error.
2. Write each key of an object on its own line in the form 'key: value'.
3. Nested objects are placed one level deeper, starting with two spaces.
4. Each array item is written with a '- ' marker; objects inside arrays are indented by the same rule.
5. Convert strings, numbers, booleans and null into YAML notation and output the result as a YAML document.

This is not a mathematical formula but a data conversion algorithm. Parsing follows RFC 8259, and the output format follows the YAML 1.2.2 specification. The data structure and values are preserved; only the delimiters and indentation change.

What the inputs mean

JSON
The JSON text to convert. It can be on one line or indented. It must be valid JSON; single quotes and trailing commas are not accepted.

Worked example: Converting release settings to YAML

  1. Input: {"debug":false,"ports":[80,443]} is a one-line JSON object.
  2. The object has two keys: debug, a boolean false, and ports, an array of two numbers.
  3. The debug line is written as 'debug: false'.
  4. ports becomes a list one line below, each item starting with '- ' and indented by two spaces.

Result: The output is a valid four-line YAML document: debug: false, then ports: followed by - 80 and - 443.

🔁 JSON to YAML Converter

Free, no sign-up; your data stays in your browser.

Open the calculator →

How to read the result

In YAML the indentation defines the structure, so be careful when you edit the output by hand; one misplaced space changes the meaning. Numbers are carried over as they are, but JSON.parse reads 1.50 as 1.5, and that difference shows in the output. Check the schema of the target system before using the file in a configuration. This is general information.

Common mistakes

  • Leaving single quotes in the JSON; under the JSON rules this text cannot be parsed at all.
  • Reading the YAML output as if it were JSON with braces; YAML shows structure with indentation and colons.
  • Fixing indentation with tab characters; YAML does not accept tabs.
  • Not noticing that 1.50 becomes 1.5; the numeric value is the same, but the notation changes.
  • Converting and sharing JSON that contains an environment variable, password or API key; the output holds the same secret.

Frequently asked questions

Can the output be applied to Kubernetes directly?

The syntax is valid, but each resource type has its own fields. Check the manifest against the schema of your target version.

Is any data lost when JSON becomes YAML?

The values are preserved. Only the notation changes, so JSON-specific details such as a number written as 1.50 are normalised.

Is my file sent to a server during conversion?

No. The conversion runs in your browser, although masking secrets before sharing is still a good habit.

Does converting YAML back to JSON change the data?

Usually not. However, number notation is simplified, and comments in the YAML are not carried back.

The result is not exact or binding and is for information only; it is not an official document and cannot be used in official procedures. Confirm it with the competent authority or a professional before acting; no liability is accepted for losses arising from its use.

Sources

Choose your cookie preference to continue

Records the site needs to work (theme, language, favourites) stay in your browser.

This site is free and funded by ads.

With your consent, Google Analytics cookies measure visits and Google AdSense cookies are used to show ads; the data is processed on Google servers abroad.

If you reject, the site works just the same.

Cookie Policy · KVKK notice