JSON to YAML Converter

Convert JSON to YAML while preserving the nesting

Runs in your browserUtility02Converters

What is JSON to YAML Converter?

A JSON to YAML converter turns a JSON object into YAML indentation syntax level by level, which is what you need when moving an API response or a config fragment into YAML-first formats such as Kubernetes manifests and CI pipelines. The conversion runs inside the browser and nothing is uploaded.

How to use JSON to YAML Converter

  1. 1Paste your JSON into the input box; the tool validates that it is well-formed first.
  2. 2Choose an indentation width — 2 spaces is the norm across the Kubernetes ecosystem.
  3. 3Copy the YAML on the right and paste it into your target config file.
  4. 4For the opposite direction, switch to the YAML to JSON tool.

How do I do this in code?

Use the tool above for one-off work; for anything you repeat, move it into a script or your project.

import yaml from 'js-yaml';

const text = yaml.dump(JSON.parse(raw), { indent: 2, lineWidth: 120 });

Common errors and how to fix them

SymptomCauseFix
The quotes around converted strings are goneMost YAML strings do not need quotes, so dropping them is ordinary normalization.Add the quotes back by hand for values like true, 123, or on that would otherwise be read as a different type.

Frequently asked questions

Does converting JSON to YAML lose any data?+

No — JSON is a subset of YAML, so every value survives the conversion. Quoting is the one thing to watch: YAML strips unnecessary quotes, so a string value that looks like a boolean or a number may be read back as that type. Keep those values quoted.

Why does my YAML output contain |- or >-?+

Those are YAML block scalars, used for long strings that contain line breaks. |- keeps the newlines and trims the trailing blank line, while >- folds newlines into spaces. Both are equivalent representations of the same string and do not change the parsed result.

Related tools

All tools