Skip to content
gohacks.dev
DevOps

YAML to JSON Converter

Convert YAML to JSON and JSON to YAML, with multi-document files, anchors and the YAML 1.2 rules Docker Compose and Kubernetes use.

Free · No sign-up · Your inputs stay in your browser

Input

Convert YAML to JSON and back

Output

Result

314 characters

Parsed with js-yaml under the YAML 1.2 core schema, where yes, no, on and off are strings, not booleans. Docker Compose and Kubernetes follow 1.2; old YAML 1.1 parsers (PyYAML) still turn NO, the country code for Norway, into false.

Runs in this browser. Nothing you paste is sent to a server.

YAML is a superset of JSON

Since YAML 1.2, every JSON document is valid YAML, so JSON can be pasted into a Compose file or a Kubernetes manifest as it is. The reverse is not true: YAML has comments, anchors and aliases, multi-line strings and several documents per file, none of which JSON can represent. Comments are lost in conversion.

The Norway problem

YAML 1.1 read yes, no, on and off as booleans, so a list of country codes containing NO came back with false in it. YAML 1.2's core schema reads them as strings. PyYAML still follows 1.1, which is why a file can mean different things to two tools. Quote any value that must stay a string.

Indentation

YAML forbids tabs for indentation. A tab, or a non-breaking space pasted from a web page, is the most common cause of a parse error on a line that looks fine.

Share

Frequently asked questions

Why does my YAML say 'bad indentation of a mapping entry'?
A key is indented differently from its siblings, or a tab or non-breaking space is used for indentation. YAML allows only spaces.
Are YAML anchors kept when converting to JSON?
They are expanded: every alias is replaced by a copy of the anchored value, because JSON has no references.
Is what I paste sent anywhere?
No. The tool runs entirely in your browser with JavaScript. Nothing you type or paste is sent to our server or stored.

Keep planning

Similar tools