
YAML to JSON: When to Convert, How It Works, and What Gets Lost
📷 Olia Danilevich from Pexels / PexelsYAML to JSON: When to Convert, How It Works, and What Gets Lost
YAML and JSON are two sides of the same coin — human-readable config vs machine-friendly data. Learn when and why to convert between them, what the tricky edge cases are, and how to do it in seconds.
A few years back I was helping a team migrate their CI/CD pipeline from one platform to another. The old system used JSON for its pipeline definitions. The new one used YAML. Not a huge deal in theory — both formats describe the same hierarchical data, right?
In practice, I spent an embarrassing amount of time manually reformatting braces into indentation, removing quotes from keys, and remembering that JSON's null becomes YAML's ~ or just null depending on your parser mood. It was tedious, error-prone work. Eventually someone pointed me toward a converter tool and I felt genuinely stupid for not using one from the start.
That experience is pretty common. YAML and JSON are everywhere in modern development — CI configs, Docker Compose, Kubernetes manifests, API responses, package metadata — and they overlap constantly enough that you will eventually need to move data between them. Understanding what each format actually is, when to use each one, and what happens when you convert makes the whole thing much less painful.
What YAML and JSON Actually Are
Neither YAML nor JSON is a programming language. They are data serialization formats — ways of representing structured data as text so that different systems can read and write it.
JSON (JavaScript Object Notation) was designed in the early 2000s as a lightweight alternative to XML for sending data between web clients and servers. It is strict, minimal, and explicit: every string is quoted, every object is wrapped in curly braces, every array is wrapped in square brackets, and there are exactly six value types (string, number, object, array, boolean, null). JSON has no comments, no multi-line strings without escaping, and no way to reference a value you defined earlier. What it lacks in expressiveness it makes up for in simplicity — virtually every language in the world can parse JSON without a third-party library.
YAML (YAML Ain't Markup Language — yes, recursive) came a bit later and was designed explicitly for human readability. It uses indentation to express nesting, allows unquoted strings in most cases, supports comments with #, and has anchors and aliases that let you define a value once and reference it multiple times. It also has a much richer type system than JSON — timestamps, binary data, sets, ordered maps. And crucially, YAML 1.2 defines itself as a superset of JSON, meaning any valid JSON document is also valid YAML.
In practice, JSON is the format you use when you are talking to APIs and need reliable machine-to-machine communication. YAML is the format you use when humans are writing and maintaining the config — because indentation is faster to scan than brackets, and comments are invaluable in config files.
When You Actually Need to Convert
The need comes up more often than you might expect:
CI/CD platform migrations. Different platforms have different preferences. GitHub Actions uses YAML. Some older Jenkins configurations use JSON or XML. If you are moving between them, the pipeline definitions need converting.
Kubernetes and REST APIs. kubectl happily accepts YAML. The Kubernetes API itself works in JSON. If you are scripting against the API directly (via curl, for example), you need JSON. If you are writing manifests for humans to read and commit to git, you want YAML. Converting between them is routine.
Config files to application defaults. Many applications ship default configs as JSON (because it is machine-generated) but document them as YAML (because humans read the docs). If you are copying settings from the docs into a programmatic config file, you need the conversion.
Reading and understanding someone else's config. Sometimes you inherit a YAML file you need to pass to a library that expects JSON, or vice versa. The conversion itself is the whole task.
Debugging API responses. APIs return JSON. You might want to inspect a response, edit it, and replay it — and doing that in YAML is sometimes easier to read. Convert in, edit, convert out.
What a YAML-to-JSON Converter Actually Does
Under the hood, the conversion is two steps: parse the YAML into an in-memory data structure, then serialize that structure as JSON.
The parsing step is where the interesting (and occasionally frustrating) work happens.
YAML anchors and aliases are resolved. YAML lets you define a value with &anchor and reference it elsewhere with *alias. This is incredibly useful in config files where you want to define your database settings once and reuse them across environments. When you convert to JSON, the anchor is gone — the referenced value is just repeated inline everywhere it was used. The resulting JSON is correct but more verbose.
Type inference happens. YAML does implicit typing. A bare true becomes a boolean. 42 becomes an integer. 3.14 becomes a float. 2026-04-21 becomes a date in some parsers. JSON has no dates and no ints vs floats distinction in the spec — just "number." A good converter handles all of this sensibly, but it is worth knowing that the YAML type system is richer than JSON's.
Comments are dropped. This is the loss that stings most. If your YAML config has helpful comments explaining why a timeout is set to 30 seconds or what a cryptic flag does, those comments are gone after conversion. JSON has no comment syntax. There is no way around this.
Multi-line strings are collapsed. YAML has block scalars — ways of writing multi-line strings using | (literal block) and > (folded block). These convert to regular JSON strings with \n newlines inside them. Technically correct, much less readable.
The Tricky Bits: YAML 1.1 vs 1.2 Boolean Headaches
This one has bitten people badly enough that it deserves its own section.
In YAML 1.1 (which most parsers were using for years), the following values are all treated as booleans:
true, false, yes, no, on, off
TRUE, FALSE, YES, NO, ON, OFF
True, False, Yes, No, On, Off
That means a perfectly innocent YAML key like enabled: yes becomes "enabled": true in JSON. And country: NO — maybe that is an ISO country code for Norway? — becomes "country": false.
YAML 1.2, which was published in 2009 and updated in 2021, fixed this by restricting booleans to just true and false. But a surprising number of YAML parsers still implement 1.1 rules because the ecosystem built up around them.
The safe rule: in any YAML file that might get converted or parsed by unfamiliar tools, quote any string that looks like a boolean. Write country: "NO" and enabled: "yes" if you mean strings. This is the kind of thing that causes a bug that takes three hours to track down and five seconds to fix.
There are also number edge cases. YAML 1.1 treats numbers with leading underscores as valid (they are not in JSON). Octal numbers like 0755 are valid in YAML but not in JSON. A good converter handles these, but they are another place where the round-trip can surprise you.
Is the Conversion Round-Trip Safe?
Short version: mostly, but not perfectly.
YAML to JSON to YAML loses comments, loses anchor definitions (you get repeated values instead), and loses any formatting choices you made in the original YAML. The resulting YAML will be valid and correct, but it will look like it was generated by a machine (because it was).
JSON to YAML to JSON is actually quite safe for standard JSON. Since JSON is a subset of YAML, the round-trip preserves all data. The only potential weirdness is if the YAML serializer makes type decisions you did not expect — quoting numbers that should stay numbers, for example.
The practical upshot: use conversion for one-way or same-direction tasks. If you need to maintain a YAML config alongside a JSON representation, keep one as the source of truth and generate the other. Do not try to keep both in sync manually after conversion.
Using the YAML-to-JSON Tool at ToolboxHubs
The YAML-to-JSON converter at toolboxhubs.com handles all of the above without you needing to think about it. Here is how to use it:
- Paste your YAML into the left panel. It accepts everything from simple key-value configs to deeply nested Kubernetes manifests.
- See the JSON output appear instantly in the right panel. The conversion runs in your browser — nothing is sent to a server.
- Copy the result. Hit the copy button and you are done.
The tool handles anchors, multi-line strings, all the boolean types, null values, and nested structures. It also validates your YAML as you type — if there is an indentation error or a malformed document, you will see an error message rather than silently wrong output.
One thing it does not do: preserve YAML comments. There is no way to put comments in JSON, so they are dropped on conversion. This is not a limitation of the tool — it is a limitation of JSON as a format.
If you want to go the other direction, the JSON-to-YAML converter is the reverse tool. Same principle, opposite direction.
Related Tools That Pair Well With This One
YAML Validator — Before converting, it helps to know your YAML is actually valid. Paste it in and see any syntax errors highlighted immediately.
JSON Formatter — After converting, the JSON might come out as one long line. The formatter pretty-prints it with configurable indentation.
JSON to YAML — Going the other direction? Same workflow, reversed.
When to Use YAML vs JSON (the opinionated take)
Use YAML when humans are the primary authors and readers. Config files, CI pipeline definitions, Kubernetes manifests, Ansible playbooks — these live in version control and get read, reviewed, and debugged by people. YAML's readability and comment support genuinely matter here.
Use JSON when machines are the primary producers or consumers. API responses, database records, generated configuration, data interchange between services — these do not benefit from human readability because no human is writing them by hand. JSON's strictness and universal support are what matter.
When you are at the boundary — receiving JSON from an API but configuring a YAML-based system, or the reverse — conversion is just a tool in the workflow. The important thing is understanding what can change in the conversion and checking for it when something goes wrong.
The YAML-to-JSON converter at toolboxhubs.com handles the mechanical part. The understanding of what gets lost is what this post was for.
FAQ
What is the main difference between YAML and JSON? YAML prioritizes human readability through indentation, comments, and flexible typing. JSON prioritizes strict structure and universal machine parsability. YAML 1.2 is a superset of JSON — valid JSON is valid YAML — but the two formats have different strengths that drive which you use where.
Does YAML to JSON conversion lose any data? Comments are always lost. YAML anchors get resolved (repeated inline rather than referenced). Custom YAML tags are dropped unless handled explicitly. For standard config files with plain strings, numbers, booleans, lists, and maps, conversion is lossless.
What are the YAML boolean gotchas?
YAML 1.1 treats yes, no, on, off as booleans alongside true and false. So country: NO converts to "country": false in JSON. YAML 1.2 restricts booleans to just true and false, but many parsers still use 1.1 rules. Quote ambiguous values in YAML to be safe.
Can I round-trip YAML through JSON and back? Structurally yes, but you lose comments, anchors, and formatting. The data will be correct; the document will look machine-generated. For config files you maintain by hand, keep the YAML as the source of truth and generate JSON from it rather than trying to keep both in sync.
Is YAML a superset of JSON? Per the YAML 1.2 spec, yes. In practice, most modern parsers handle JSON embedded in YAML without issues. The edge cases are around YAML 1.1 parsers and certain number formats that JSON rejects.