DevToolbox

JSON to YAML

Convert JSON to YAML and YAML to JSON

JSON input

Paste or type JSON
Loading...

YAML output

Output will appear here

Related tools

What is JSON to YAML conversion?

YAML and JSON can hold the same data: objects, arrays, strings, numbers, true, false, and null. This converter writes JSON as YAML and YAML as JSON with the yaml library, following YAML 1.2. Numbers and key order are kept exactly, strings that YAML would read as something else are quoted, and YAML's comments, anchors, aliases, merge keys, and multiple documents are read correctly. Invalid input gets an error with its line and column, and everything runs in your browser.

JSON to YAML

Objects become mappings, arrays become sequences indented with -, and nesting is shown with two spaces per level. Keys keep their order, and numbers are written exactly as they appear in the JSON, so 12345678901234567890 stays 12345678901234567890 instead of being rounded the way JavaScript's JSON.parse rounds it.

Most strings are written without quotes, but any string YAML would read as something else is quoted: "null", "1.10", "01234", and strings YAML would read as a comment, a sequence item, or an alias, such as "# note", "- item", or "*ref". The quoting also covers values that only YAML 1.1 parsers misread, such as "NO", "yes", "on", and "12:30" (the "Norway problem"), so the YAML means the same to YAML 1.1 and YAML 1.2 parsers. A string with line breaks becomes a block scalar (|-), and characters YAML can't hold as they are, such as control characters, are escaped in double quotes.

YAML to JSON

The YAML is read as YAML 1.2: comments are dropped, flow collections such as [a, b] and {x: 1} are read, block scalars (| and >) keep their line breaks, anchors and aliases (&base, *base) are expanded, and merge keys (<<: *base) copy the merged keys in. Integers in any notation (0x1F, 0o17) are written as decimals, and every number is written without rounding.

In YAML 1.2, yes, no, on, and off are strings, not booleans, so they stay strings in the JSON; the converter warns where a YAML 1.1 parser would read them differently. Several documents separated by --- become a JSON array with one item per document. Values JSON can't hold are errors with their line and column: .inf and .nan, and keys that are mappings or sequences. Keys that aren't strings become strings: 1 as "1", true as "true", and null or ~ as "null".

What doesn't survive the trip

The data converts exactly both ways, but some things only exist in one format. YAML comments, anchors, and the choice of quoting or block style aren't part of the data, so they aren't in the JSON, and converting the JSON back gives the same data without them. Custom tags such as CloudFormation's !Ref aren't standard YAML; their values are converted as plain data, with a warning.

Errors and warnings

If the input isn't valid JSON or YAML, the converter shows the line, the column, and what's wrong, such as "Line 2, column 1: Tabs are not allowed as indentation", and Go to error moves the cursor there. Duplicate keys are an error in YAML and a warning in JSON, where the last value is used.

How to convert between JSON and YAML

  1. 1Choose a direction. Select JSON → YAML or YAML → JSON. Switching direction moves the converted document into the input, so converting back is one click.
  2. 2Paste your document. Paste JSON or YAML into the input, or load the sample. The output updates as you type, and an error shows the line and column.
  3. 3Copy the result. Copy the converted document into your config file or code, or share a link to it.

Examples

JSON to YAML

Input

{"name":"app","ports":[80,443],"debug":false}

Output

name: app
ports:
  - 80
  - 443
debug: false

Strings YAML would misread are quoted

Unquoted, YAML 1.1 reads NO and yes as booleans, and YAML reads 1.10 as the number 1.1.

Input

{"country":"NO","version":"1.10","enabled":"yes","zip":"01234","note":"# not a comment"}

Output

country: "NO"
version: "1.10"
enabled: "yes"
zip: "01234"
note: "# not a comment"

A string with line breaks

Input

{"script":"npm run build\nnpm start"}

Output

script: |-
  npm run build
  npm start

Key order and large numbers kept

Input

{"b":1,"2":2,"id":12345678901234567890}

Output

b: 1
"2": 2
id: 12345678901234567890

YAML to JSON

Input

name: app
replicas: 3

Output

{
  "name": "app",
  "replicas": 3
}

Comments, anchors, and merge keys

Input

# defaults
base: &base
  image: node:22
  restart: always
web:
  <<: *base
  port: 8080

Output

{
  "base": {
    "image": "node:22",
    "restart": "always"
  },
  "web": {
    "image": "node:22",
    "restart": "always",
    "port": 8080
  }
}

Several YAML documents

Input

a: 1
---
b: 2

Output

[
  {
    "a": 1
  },
  {
    "b": 2
  }
]

yes is a string in YAML 1.2

The converter also warns that YAML 1.1 parsers read yes as a boolean.

Input

enabled: yes
port: 0x1F90

Output

{
  "enabled": "yes",
  "port": 8080
}

Invalid YAML

No output is produced; the error is shown instead.

Input

a:
	b: 1

Output

Line 2, column 1: Tabs are not allowed as indentation.

JSON and YAML equivalents

How the two formats write the same data.

JSONYAML
{"k": "v"}k: v
[1, 2]- 1 and - 2, one per line
"NO" (a string)"NO" (quoted, or YAML 1.1 reads a boolean)
"a\nb" (two lines)|- block scalar, one line each
nullnull (or ~ in YAML)
No comments# comments, dropped in JSON
No anchors&name and *name, expanded in JSON
One valueSeveral documents (---), an array in JSON

Frequently asked questions

Is any data lost when converting?

No data is lost: keys, values, arrays, nesting, key order, and numbers (in YAML 1.2 notation) convert exactly both ways. What isn't data doesn't carry over to JSON: YAML comments, anchors (they're expanded), and quoting or block styles. YAML values JSON can't hold, such as .inf, .nan, and keys that are mappings, are errors rather than being changed silently.

Why are some strings quoted in the YAML?

Because unquoted they would mean something else. YAML reads 1.10 as a number, null as null, and # as the start of a comment, and YAML 1.1 parsers also read yes, no, on, and off as booleans (NO, the code for Norway, becomes false). The converter quotes exactly those strings, so the YAML holds the same data for any parser.

Which YAML version does it follow?

YAML 1.2, the current version, with the core schema, as the yaml library implements it. Reading YAML, it warns where a YAML 1.1 parser would read a value differently, and a document that starts with %YAML 1.1 is read as YAML 1.1. Writing YAML, it quotes values so YAML 1.1 parsers read them the same way too.

Does it support anchors, merge keys, and multiple documents?

Yes. Anchors and aliases are expanded, merge keys (<<) copy the merged keys in, with keys written in the mapping taking precedence, and several documents separated by --- become a JSON array. Aliases that would expand to a huge amount of data (the billion-laughs attack) are an error.

What happens to YAML comments?

JSON has no comments, so they're dropped in the JSON. YAML allows comments starting with #, one reason it's preferred for configuration files.

What does switching direction do?

It moves the converted document into the input and converts it back, so you can check a round trip or keep editing in the other format. If there's no converted document yet, the input is cleared.

Is my data private?

Yes. Conversion happens in your browser, and nothing you enter is sent to a server. The only exception is the Share link button, which uploads your input and the converted output when you click it, so the link can reopen them.

Is it free?

Yes — free and unlimited.