YAML and JSON converter
Everything runs in your browser; nothing is sent or stored.
- Paste your input into the "YAML or JSON" field, and click "YAML to JSON" or "JSON to YAML".
- Under "YAML indentation", choose "2 spaces" or "4 spaces", and in the "YAML line width" field, choose the length above which a string is split.
- The indentation and line width settings apply only when converting to YAML, and a JSON result is always indented with 2 spaces.
- Select "Several documents as an array" to always get an array when converting to JSON, and a separate document for each item of the array when converting to YAML.
- The key order is kept. From YAML to JSON, anchors and aliases (& and *) and merge keys (<<) are expanded into full values, and comments are not kept, because JSON has no place for them. From JSON to YAML, a string such as yes or on is written in quotes, so it is not read as a boolean value.
- Custom tags are not resolved and do not run code, and the number of aliases is limited to prevent an expansion attack (Billion Laughs).
- Below the result, the tool shows its number of characters and messages about values that changed in the conversion.
- Copy the result by clicking "Copy".
Differences between YAML and JSON
JSON is used mainly for exchanging data between systems, and YAML is used mainly for configuration files that people write and read, such as a docker-compose.yml file, Kubernetes files, and the configuration files of CI pipelines. In YAML, the structure is set by the indentation, you can write comments that start with #, and you can define a value once with an anchor (&) and refer to it with an alias (*). A JSON document is usually also a valid YAML document, so the conversion to JSON also accepts JSON input. When converting to JSON, comments are not kept, because JSON has no place for them.
Anchors, merge keys, and tags when converting to JSON
When converting to JSON, every alias is replaced with a full copy of the value it refers to, and a merge key (<<) copies the keys of the anchor into the object. This way, all the values appear explicitly in the result, even when they were defined once in the original file. Custom tags, such as !Ref in AWS CloudFormation templates, are not resolved, and the value after them is kept as text, with a message showing the number of tags. The number of aliases is limited to prevent a small file from expanding into a huge amount of data, as in a Billion Laughs attack.
Values that change type in the conversion
In YAML, an unquoted value is read according to its form: true is a boolean value, 8080 is a number, and ~ is null. The converter reads YAML according to the current YAML specification, in which yes, on, and no are text, but older YAML readers read them as boolean values. That is why, when converting to YAML, text that looks like a boolean value is written in quotes, so that every YAML reader reads it as text. A postal code with a leading zero and a version number need to be written in quotes in the original file, because without quotes they are read as numbers, and the value changes in the conversion.
YAML values and what they become in JSON
port: "8080"the quoted value stays the text"8080".enabled: yesthe value stays the text"yes"and does not becometrue.zip: 01234the value becomes the number1234, and the leading zero is removed.version: 1.10the value becomes the number1.1, and the trailing zero is removed.timeout: .infthe value becomesnull, because JSON has no way to represent infinity.<<: *defaultsthe keys of thedefaultsanchor are copied into the object.id: !Ref Bucketthe tag is not resolved, and the value is the text"Bucket".
YAML and JSON converter FAQ
Why do I get an error for a YAML file that looks valid?
An error in a YAML file that looks valid is often caused by indenting with a tab, because YAML indentation must use spaces only. Another common error is two keys on the same line, without a line break between them. The error message shows the line and the column, and after you click a conversion button, the cursor moves to the location of the error in the input field.
Why do I get a duplicate key error?
A key can appear only once at the same level of the same object, so the converter shows an error with the line and the column of the repeated key, and does not choose one of the values. A duplicate key often appears when a block is copied into a file and the previous block is not deleted.
Can I convert a YAML file with several documents?
Yes. You can convert a file in which the documents are separated by a line of three hyphens, such as a Kubernetes file with several resources. The result is a JSON array in which each document is an item, in the order of the documents in the file.
Is the key order kept in the conversion?
Yes. The key order is kept in both directions, as it appears in the input, so you can easily compare the original file with the result.
Why did a long number change in the conversion?
An integer greater than 9,007,199,254,740,991 is not kept exactly, and its last digits may change in the result. To keep the exact value of a long ID, write it in quotes, as text.
What is the maximum size of a YAML or JSON file to convert?
The input can be up to 1 MB, and the result can be up to 4 MB. A nested structure is processed up to a depth of 100 levels, and a YAML file can contain up to 10,000 documents.