Paste a YAML file and copy out the same settings as JSON, ready for a program that reads nothing else.
FluffyShieldProtected workspace
Loading the tool…
The tool didn't load. Reload the page, or check whether an extension or network filter blocks .
Free · No upload · No sign-up · No usage quotas
Why is the JSON so much longer than the YAML?
YAML can write a group of settings once and point to it from anywhere else in the file. JSON has no way to point, so every pointer turns into a full copy.
FluffyBench · 4 min read · Reviewed
From YAML to JSON
Read the file by the YAML 1.2 rules
→Put a copy of the named block wherever a pointer was
→Write the whole thing out as JSON
What it does
Dates stay as typed
A date written as year, month and day comes out as the same characters in quotes. Nothing turns it into a date.
Comments are left out
JSON has no comments, so the note at the top of the file doesn't make the trip. The line under the result says so.
Several documents, one list
A file with documents split by --- lines comes out as a JSON list, one entry per document. Our two-document test gave two entries, in file order.
Limits YAML 1.2 only: a file that opens with a %YAML 1.1 line is refused.
A compose file where two services share their logging
Your shop's website runs as two programs: a web server, and a worker that sends out the order emails. Both are started from a compose file, a YAML file that lists the programs and the settings each one runs with. You want both to keep their logs the same way, so the logging settings are written once, near the top under the name x-logging, and each service, as the file calls each program, points to them.
The pointing takes two marks. &logging puts a name on the block; the YAML 1.2 specification calls that an anchor. *logging further down, called an alias, means "the block named logging goes here". It works like a cookbook that says "make the pastry from page 12" instead of printing the pastry recipe again under every pie.
Now a hosting panel you use wants the same settings as JSON, so you paste the file in here.
One block, three copies
The log limit is written once in the YAML and three times in the JSON, and the file grew from 13 lines to 28. How we checked
Why JSON prints the block every time
JSON has no mark that means "same as over there", so the converter does the one thing that keeps your settings the same: it puts a full copy of the block wherever an alias stood. A program reading the JSON gets exactly what a program reading the YAML got.
The trouble starts the day you change something. Raising the log limit from 10m to 50m is one edit in the YAML. In the JSON it's three, and if you miss one, the worker quietly keeps a different limit from the web server. Nothing in the JSON tells you the copies were ever meant to match.
So treat the YAML as the file you change, and the JSON as something you make from it when it's needed. Making it again is one paste; hunting down a copy you forgot to update is not.
Turning your compose file into JSON
Paste the whole compose file into the YAML box, comments and all.
Read the JSON on the Result tab, or beside the YAML on a wider screen. Each service now has its logging block written in full.
Press Copy to take the JSON with you.
When a service borrows the block and adds to it
Some files go a step further and write <<: *defaults inside a service: take everything in the defaults block, then add this service's own settings to it. That << is a merge key, a key being the name before a colon. It was defined for YAML 1.1 and left out of YAML 1.2, but Docker Compose and GitLab pipeline files still use it, so this converter does too.
Pasted with a merge key under web, our file converted, and web came out with two settings: restart: always from the defaults block and its own image. The line under the result adds "Merge keys (<<) are written out in full."
A setting written in the service itself wins over the same setting in the block it borrows. Write the key in quotes, "<<", when it is an ordinary name and not a merge.
You want the YAML itself tidied, comments and anchors kept