DEVELOPER TOOL

YAML to JSON Converter (and JSON to YAML)

Paste YAML to get JSON, or flip the direction to turn JSON into YAML. Errors point to the exact line and column, and nothing is uploaded.


  

About this tool

YAML and JSON describe the same kinds of data, maps, lists, strings, numbers, booleans and null, so most documents can move between them without loss. YAML is easier for people to write and is common in configuration files such as Kubernetes manifests, GitHub Actions workflows and Docker Compose files. JSON is what most APIs and programming languages expect. This converter works in both directions using js-yaml 4.1.0, an open-source YAML parser, and runs entirely in your browser.

How to use the converter

  1. Pick a direction. YAML → JSON is selected by default. Choose JSON → YAML, or click Swap direction to move the current output into the input box and convert it back.
  2. Paste your YAML or JSON into the input box.
  3. Choose an indent of 2 or 4 spaces for the output.
  4. Click Convert. If the input has a syntax error, the status line gives the line and column, and the output box shows the offending lines.
  5. Copy or download the result as a .json or .yaml file.

YAML 1.2 and JSON

The YAML 1.2 specification says the main focus of version 1.2 was making YAML a strict superset of JSON. In practice that means you can paste plain JSON into the YAML → JSON direction and it will parse. The reverse is not true: comments, anchors and unquoted strings are YAML features with no JSON equivalent.

The Norway problem: is no a string or false?

YAML 1.1 defined a long list of words as booleans: y, yes, on, n, no and off in several capitalizations, alongside true and false. A list of country codes containing NO for Norway would therefore load as false, which is where the nickname comes from. The YAML 1.2 Core schema narrows booleans to true, True, TRUE, false, False and FALSE.

js-yaml 4.1.0 follows the 1.2 rule. In this tool country: no, a: yes, a: on and a: NO all come out as strings, while a: True becomes the boolean true. Going the other way, js-yaml puts quotes around strings such as 'no', 'yes', 'on' and 'y' when it writes YAML, so an older YAML 1.1 parser will still read them as text. If your YAML will be read by a tool that uses YAML 1.1 rules, quote such values yourself.

Anchors, aliases and merge keys

YAML lets you mark a node with an anchor (&name) and repeat it elsewhere with an alias (*name). JSON has no references, so each alias is expanded into a full copy of the anchored data. The YAML 1.1 merge key << is also supported: <<: *defaults copies the keys of the anchored map into the current one, and keys written explicitly next to it take priority. The anchor names themselves do not appear in the output.

Worked example

The sample in the tool uses a comment, an unquoted no, a flow-style list and a merge key. Converting it to JSON with a 2-space indent gives:

{
  "service": "checkout",
  "replicas": 3,
  "debug": false,
  "country": "no",
  "ports": [
    8080,
    8443
  ],
  "defaults": {
    "timeout": 30,
    "retries": 2
  },
  "staging": {
    "timeout": 60,
    "retries": 2
  }
}

The comments are gone, country is the string "no", and staging has received retries: 2 from the anchored defaults while keeping its own timeout of 60. Click Swap direction and the JSON converts back to YAML with country: 'no' quoted, the list in block style and staging written out in full, since the anchor was not kept.

Multi-document YAML

A YAML stream can hold several documents separated by --- lines, which is common in Kubernetes manifests. When the input has more than one document, the JSON output is an array with one element per document, and the status line says how many were found. A document with nothing in it becomes null. In the JSON → YAML direction, tick the multi-document option to write each element of a top-level array as its own --- document.

What does not survive the conversion

Common mistakes

To check or pretty-print the JSON result, use the JSON Formatter, or compare two versions with JSON Diff. For tabular data, the CSV to JSON Converter may be a better starting point.

Frequently asked questions

How do I convert a Kubernetes YAML file to JSON?

Open the manifest, copy all of it, and paste it with YAML to JSON selected. If the file has several resources separated by --- lines, the output is a JSON array with one object per resource. kubectl can also read JSON manifests, so the converted output can be applied directly.

Is JSON valid YAML?

For practical purposes, yes. YAML 1.2 was designed as a superset of JSON, so a YAML 1.2 parser reads ordinary JSON documents as YAML. You can test this by pasting JSON into the YAML to JSON direction; the output will be the same data, reformatted.

Why are some strings quoted in the YAML output but not others?

Strings are quoted only when leaving them bare would change their meaning. Text like 123, true, null or 2026-10-07 would load as a number, boolean, null or date, and words like yes and no would be booleans for YAML 1.1 parsers, so they get single quotes. Ordinary words stay unquoted.

Can I keep comments when converting JSON to YAML?

JSON has no comment syntax, so there are no comments to carry over. After converting, you can add YAML comments by hand with a # at the start of a line or after a value. Keep in mind they will be lost again if the YAML is converted back to JSON.

Why does the error say line 2 when my mistake is on line 1?

A parser reports where it noticed the problem, which can be after the real mistake. An unclosed bracket or quote, for example, is only detected when the parser reaches the end of the input. Check the reported line and the lines just above it.

Does this converter support YAML tags like !Ref or !!binary?

Standard tags such as !!str, !!int and !!float work, so !!str 123 gives the string 123. Custom application tags such as !Ref or !GetAtt in AWS CloudFormation templates are not defined in the default schema, so the parser reports an unknown tag error. Rewrite them in their long form, such as Ref: or Fn::GetAtt:, before converting.