YAML to JSON Converter

Paste YAML (a docker-compose file, a GitHub Actions workflow, a Kubernetes manifest) and get JSON, or switch the direction for JSON to YAML. Errors show the exact line and column. Nothing leaves your browser.

FreeNo sign-upRuns in your browser: your data is not uploaded

When you need YAML as JSON

Config files are written in YAML because people can read it: docker-compose, GitHub Actions, GitLab CI, Kubernetes, OpenAPI specs, Laravel Sail. Many APIs, scripts and validators only take JSON. YAML and JSON describe the same data (maps, lists, strings, numbers, true/false, null), so the conversion is exact. What does not survive is YAML-only material: comments, anchors (they are expanded into full copies) and the order of keys in some tools.

The YAML errors you will meet most

  • Tabs for indentation: YAML only allows spaces. A tab that looks fine in your editor breaks the file. The error view shows tabs as →.
  • Misaligned items: keys at the same level must start in the same column, and list dashes must line up.
  • Missing space after the colon: name:headsntail is one string, not a key and a value. Write name: headsntail.
  • Duplicate keys: the same key twice in one block is an error here, because most parsers would silently keep only the last one.
  • Values that change type: version: 8.10 becomes the number 8.1, and country: NO stays the text "NO" in YAML 1.2 but is false in old YAML 1.1 tools. Quote values that must stay text: version: "8.10".

Multi-document files

Kubernetes and some CI files hold several documents separated by ---. By default the first document is converted. Tick All documents to get a JSON array with one item per document.

JSON to YAML

Switch the direction to turn JSON into YAML, for example an API response you want to put in a config file. Strings are quoted only when they need it, and you can sort keys A-Z to make two files easy to compare.

Doing it in code

  • Command line: yq -o=json file.yaml (yq v4).
  • PHP: with the Symfony YAML component, json_encode(Yaml::parseFile('config.yaml'), JSON_PRETTY_PRINT).
  • Python: json.dumps(yaml.safe_load(open('config.yaml')), indent=2) with PyYAML.

To check or tidy the JSON afterwards, use the JSON formatter. For a PHP array, use JSON to PHP array.

YAML parsing: js-yaml 4.1.0 (MIT), YAML 1.2 core schema.

FAQ

Is my YAML sent to a server?
No. Parsing and conversion run in your browser, so you can paste config files safely. Still, remove passwords and API keys before pasting secrets into any online tool.
Why do I get "bad indentation of a mapping entry"?
A key is indented more or less than the keys next to it, or a tab is used instead of spaces. The error shows the line and column; line the key up with its neighbours using spaces.
What happens to YAML comments?
JSON has no comments, so they are dropped. Anchors and aliases (& and *) are expanded into full copies of the data.
Can it convert a file with several documents?
Yes. Files with --- separators are read in full. Tick "All documents" to get every document as an item in a JSON array; otherwise only the first is shown.
Can I convert JSON back to YAML?
Yes. Choose JSON → YAML in Direction, or press Swap to send the current result back the other way.

Found it useful? Put a link in your docs, README or forum answer so others can use it too:

HTML
<a href="https://headsntail.com/tools/yaml-to-json">YAML to JSON Converter</a> (free, by HeadsNTail)
Markdown (GitHub, Stack Overflow, dev.to)
[YAML to JSON Converter](https://headsntail.com/tools/yaml-to-json)

Need it done on your server? HeadsNTail sets up Laravel apps, cPanel hosting and migrations for businesses. See services or ask a question.