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:headsntailis one string, not a key and a value. Writename: 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.10becomes the number 8.1, andcountry: NOstays the text "NO" in YAML 1.2 but isfalsein 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?
Why do I get "bad indentation of a mapping entry"?
What happens to YAML comments?
Can it convert a file with several documents?
Can I convert JSON back to YAML?
Link to this tool
Found it useful? Put a link in your docs, README or forum answer so others can use it too:
<a href="https://headsntail.com/tools/yaml-to-json">YAML to JSON Converter</a> (free, by HeadsNTail)
[YAML to JSON Converter](https://headsntail.com/tools/yaml-to-json)
Share: X LinkedIn Reddit WhatsApp
Need it done on your server? HeadsNTail sets up Laravel apps, cPanel hosting and migrations for businesses. See services or ask a question.