Convert JSON to YAML
What converting JSON to YAML changes, where data types can shift, and how to check that the result stays readable and usable after you copy or share it.
Converting JSON to YAML is usually done for readability. Configuration files, deployment manifests and documentation examples are easier to scan when braces and quotation marks give way to indentation. The conversion is not always neutral, though. This review covers what the transformation changes, where meaning can shift, and when plain JSON is the better choice.
Is converting JSON to YAML right for your use?
Converting from JSON to YAML suits files that people read and edit by hand, such as configuration and infrastructure definitions, and any destination that expects YAML. The main benefit is lighter syntax: fewer brackets and quotes, and the option to add comments after conversion. The decisive tradeoff is that YAML relies on whitespace and implicit typing. An indentation error or an unquoted value can change what the data means, and the file can still look correct.
Keep plain JSON when:
- The data is exchanged between programs, such as API payloads, logs or messages, and nobody needs to read it.
- The receiving system documents JSON as its input format.
- Strict, unambiguous typing matters more than readability.
- The text will pass through channels that may alter whitespace, such as chat apps, rich-text editors or email.
- The destination's YAML parser is unknown, so it is unclear how values like "no" or "1.10" will be interpreted.
Converting may also be unnecessary. The YAML 1.2 specification was designed so that JSON text is, with minor edge cases, also valid YAML. A YAML 1.2 parser can often read a JSON file as it is. Conversion is mainly a readability decision, not a compatibility requirement.
What the conversion actually changes
Converting JSON to YAML is a change of serialization format. It is not reversal, mirroring, Unicode substitution or a visual styling effect. The stored characters really change: braces, brackets and most quotation marks are removed, and structure is expressed through indentation, colons and leading hyphens for list items. The underlying data should stay the same: objects become mappings, arrays become sequences, and strings, numbers, booleans and null carry over. Whether that holds depends on how the converter handles quoting.
The illustrative pair below was written for this article. It is not output from any particular tool. Input JSON:
{
"name": "web",
"replicas": 3,
"enabled": true,
"country": "NO",
"version": "1.10",
"ports": [80, 443],
"labels": {"tier": "frontend"}
}
An equivalent YAML representation:
name: web
replicas: 3
enabled: true
country: "NO"
version: "1.10"
ports:
- 80
- 443
labels:
tier: frontend
The quotes around "NO" and "1.10" are deliberate. Without them, a YAML parser following the older 1.1 rules may read NO as the boolean false. Any YAML parser may read 1.10 as the number 1.1. In the JSON both values are strings, so a correct conversion has to keep them quoted. Other values that can be retyped when left unquoted include yes, no, on and off; strings with leading zeros such as 0123, which YAML 1.1 can treat as octal; date-like strings such as 2024-01-01, which some loaders turn into date objects; the words null and true; and strings that start with characters YAML treats as syntax, such as a colon, hash, hyphen, asterisk or ampersand.
Other ways the result can differ
- Key order: the JSON specification treats object members as unordered. Many converters keep the input order, but some libraries sort keys by default, which changes how the file reads without changing its meaning.
- Large numbers: JSON places no limit on numeric precision, but tools built on double-precision floats can silently round integers beyond about 2^53 or long decimals. Compare large IDs and amounts after conversion.
- Non-ASCII text: depending on settings, characters such as accented letters or emoji may be written as escape sequences instead of literal characters. The data is the same, but it is harder to read.
- Long or multi-line strings: these may come out as quoted strings with escaped newlines or as block scalars. Both are valid, but block scalars handle trailing newlines in ways worth checking.
- Duplicate keys: JSON parsers differ in how they treat repeated keys. A converter may keep the last value, keep the first, or reject the input.
Will the YAML stay readable and usable after copying or sharing?
Copying is riskier for YAML than for JSON because indentation carries meaning. YAML does not allow tab characters for indentation. Pasting through editors or messaging tools that turn spaces into tabs, insert non-breaking spaces, trim leading whitespace or replace straight quotes with curly ones can break the file or change its structure. A code block in the destination, or a file attachment, is safer than pasting into a rich-text field. If the YAML has to travel through an untrusted channel, sending the JSON and converting at the destination avoids this problem.
Editing is affected in the same way. Moving a block means re-indenting it consistently, and a line indented one level too deep or too shallow can attach a key to the wrong parent without causing a parse error. Validating the YAML after edits is advisable, ideally by loading it with the same parser the destination system uses.
Accessibility deserves a cautious note. In YAML, nesting is conveyed by leading spaces, while JSON has explicit brackets that a screen reader announces. Whether a screen reader user can follow YAML nesting depends on the reader's settings for announcing indentation and on the editor in use. No scoped test or assistive-technology documentation was available for this review, so no claim is made about specific tools. Where structure must be accessible, offering the JSON form or a short prose description of the hierarchy alongside the YAML is a reasonable fallback.
Search and tooling vary in similar ways. Searching for a full key path is harder in YAML, because the parent keys sit on earlier lines. Plain-text search still finds individual keys and values.
Checking a conversion before relying on it
- Parse the YAML back into data and compare it with the original JSON, using a structural comparison rather than a text diff.
- Check that strings like NO, yes, 1.10, 0123 and date-like values are still strings.
- Compare large integers and precise decimals exactly.
- Load the file with the parser or version the destination actually uses, because YAML 1.1 and 1.2 loaders interpret some plain values differently.
- If you use an online converter, do not paste secrets or personal data unless the service's documented data-handling policy is acceptable to you. A local library or command-line tool avoids sending the data elsewhere.
Evidence gaps
This review is based on the behavior of the JSON and YAML formats as specified, not on tests of particular converters. No measurements, tool comparisons, screen-reader tests or privacy documentation for specific services were available. Claims about how a given converter quotes values, orders keys or handles large numbers should be confirmed by running a sample of your own data through it.