Open tools · 0

About

YAML to JSON

Paste YAML from a Kubernetes manifest, a Compose file or a CI pipeline, and the JSON is written as you type. Anchors and merge keys are expanded into the values they stand for, several documents become one array, and a mistake, such as a tab used for indenting, is placed by line and column.

What it does

  • An alias such as *base is written out in full wherever it appears, since JSON cannot point at another value.
  • A merge key (<<) brings its keys in where it stands, and a key written in the map itself wins.
  • Documents split by --- become one JSON array in their order, and a note says how many there were.
  • Block text keeps its line breaks after | and has them folded into spaces after >.
  • Numbers JSON cannot spell are rewritten and said so: 0x1F is 31, .5 is 0.5, and .inf becomes a string.
  • Keys that are numbers or booleans become strings, the only keys JSON has.
  • Comments are dropped, as JSON has no syntax for them, and the summary says how many there were.

How to use it

  1. Paste the YAML, or drop the .yaml or .yml file.
  2. Pick the indent, or One line for the most compact JSON.
  3. Read the notes on what was expanded, rewritten or dropped.
  4. Copy the JSON, or download it.

What it does not do

  • CloudFormation’s short tags (!Ref, !GetAtt, !Sub): they mean something only to CloudFormation, so each is left off with a note, where AWS’s own JSON would write {"Ref": ...}.
  • A key written twice in one map: YAML forbids it, so the file is refused at the second one rather than one of the two picked.
  • Tabs for indenting: YAML allows only spaces there, so reading stops at that line rather than guess its depth.

Questions

Why is on: in my GitHub Actions workflow flagged?

Because PyYAML and other YAML 1.1 readers take an unquoted on as true, so a Python script reading the workflow sees the key True. GitHub reads it as the word, which is why the workflow runs. The JSON has "on", the YAML 1.2 reading.

Can JSON hold several documents?

No, a JSON file is one value, so the documents of a multi-document YAML file become the items of one array. A Kubernetes file holding a Deployment and a Service gives an array of two objects.

Is the order of the keys kept?

Yes, as the YAML has them, with merged keys in the place of the <<. Tick Sort keys for A to Z instead, which makes two JSON files easier to compare.

Why is 2024-01-01 a string and not a date?

JSON has no date type, and YAML 1.2 reads an unquoted date as text anyway. A YAML 1.1 reader would make it a date, so the value is flagged, with its line.

Everything here runs in your browser. Nothing you type, paste or open is uploaded, and there is no account and no queue. How that works.

Often used with

More in Converters

  • Unit Converter: Convert length, weight, temperature, volume, area, speed, data size and nine more quantities, both ways, with the formula.
  • Base64 Encode & Decode: Encode text or files to Base64 and decode it back: URL-safe, MIME line breaks, data URIs, and images you can preview.
  • CSV Viewer & Editor: Open a CSV, Excel or JSON file as a table, tidy it (spaces, duplicates, garbled letters, dates and numbers) and save it as CSV, .xlsx or JSON.

All toolsAbout utilbrewPrivacy