Find your next tool

Browse tools or search by task

Explore JSONToonPro

JSON Tools

JSON to YAML Converter Online – Convert JSON to YAML

Convert JSON to clean YAML online for Kubernetes, Docker and CI configs. Preserve nested objects and arrays with private browser-side conversion.

Runs locally in your browser. Nothing you paste is uploaded.

JSON to YAML workspace
Indent
34 nodes
Input/ JSON
420 chars25 lines
Output/ YAML
295 chars20 lines

How to Convert JSON to YAML

Paste valid JSON and choose indentation, key ordering and string quoting. Inspect the generated YAML before putting it into a configuration file. Keep the original JSON as a reference when the target parser has different scalar rules.

JSON vs YAML Syntax

JSON uses braces, brackets and commas; YAML often uses indentation and dash-prefixed list items. YAML comments do not have a JSON equivalent. Both can express nested maps and lists, but YAML supports features beyond JSON.

Nested Objects, Arrays and Indentation

Objects become mappings and arrays become sequences. Consistent spaces matter because indentation establishes nesting. Check a small nested sample first if a deployment system expects a particular shape, and avoid tabs for indentation.

YAML Type Coercion and Compatibility

YAML 1.1 and 1.2 differ in implicit scalar typing. Quote values such as NO, dates and numeric-looking identifiers when their string identity matters. The converter offers string quoting to reduce surprises across parsers.

JSON to YAML Examples for Config Files

A JSON object with replicas: 3 and an array of image names becomes a mapping with a numeric scalar and list. Converting syntax does not establish that the resulting Kubernetes or CI configuration meets that platform’s schema.

More examples and technical details

YAML Is a Superset of JSON

Since YAML 1.2 the specification states that every valid JSON document is also a valid YAML document. Paste raw JSON into a YAML parser and it will accept it. That fact makes this conversion less of a translation and more of a reformatting: the data model on both sides is the same set of maps, sequences, and scalars, and only the syntax changes.

What you gain is readability and comments. What you gain in risk is whitespace sensitivity and a set of implicit typing rules that surprise people. The rest of this page is about both.

Side by Side Example

A deployment configuration, first as JSON and then as the block style YAML the converter produces.

JSON input

{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": { "name": "web", "replicas": 3 },
"spec": {
"containers": [
{ "name": "api",
"image": "ghcr.io/acme/api:1.4.0",
"ports": [8080, 9090] },
{ "name": "sidecar",
"image": "envoy:1.29",
"ports": [15000] }
],
"restart": "always"
}
}

YAML output

apiVersion: apps/v1
kind: Deployment
metadata:
name: web
replicas: 3
spec:
containers:
- name: api
image: ghcr.io/acme/api:1.4.0
ports:
- 8080
- 9090
- name: sidecar
image: envoy:1.29
ports:
- 15000
restart: always

Every brace, bracket, comma, and quotation mark is gone. The structure is now carried entirely by indentation and by the hyphen that marks a sequence item.

Indentation Rules

  • Two spaces per level is the near universal convention. The spec only requires consistency, but every linter and every example you will meet uses two.
  • Tab characters are forbidden as indentation. This is a hard rule in the specification, not a style preference, and a stray tab produces a parse error that often points at the wrong line.
  • A sequence under a mapping key may be indented or written flush with the key. Both are legal, which is why you will see two different looking styles in real repositories.
  • Sibling keys must line up in the same column exactly. A single extra space silently changes the meaning by nesting the key under its predecessor.

Configure your editor to show whitespace and to insert spaces rather than tabs before you edit YAML by hand. It removes an entire category of bug.

Block Style and Flow Style

YAML supports two ways of writing collections. Block style uses indentation and is the readable default. Flow style uses braces and brackets and looks exactly like JSON, which is why the superset claim holds.

Same value, both styles

# block style
ports:
- 8080
- 9090
 
# flow style
ports: [8080, 9090]

Flow style is useful for short lists where a vertical block would waste six lines to say very little. Mixing the two in one file is entirely legal and often produces the most readable result.

When Strings Need Quoting

YAML infers scalar types from the shape of the text, and unquoted values are resolved against a set of patterns. This is convenient right up until a value happens to match a pattern you did not intend.

Written asParsed asQuote it to get a string
noBoolean false in YAML 1.1Write "no"
yes / on / offBooleans in YAML 1.1Quote the value
1.20Float 1.2, trailing zero lostWrite "1.20" for a version
1.2.3String, three dots is not a numberSafe unquoted but quoting is clearer
0755Octal integer 493 in YAML 1.1Write "0755" for a permission code
12:30Sexagesimal number in YAML 1.1Write "12:30" for a time
null / ~ / (empty)NullWrite "null" for the literal word
@handleReserved indicator, parse errorMust be quoted
*refAlias referenceMust be quoted

The Norway problem

The best known example: a list of ISO country codes containing NO for Norway. Under YAML 1.1 rules, the unquoted token no is a boolean, so Norway silently becomes false and a country vanishes from the list. The same trap catches ON for Ontario and, in some parsers, the chemical formula shorthand and any field where a two letter code is legitimate data. Quote your codes.

Multi-line Strings, Comments, and Anchors

Three YAML features have no JSON equivalent at all, and they are the main reason teams prefer YAML for configuration.

Block scalars, comments, and anchors

# A comment. JSON has no way to write this.
 
script: | # literal, newlines preserved
set -euo pipefail
npm ci
npm run build
 
summary: > # folded, newlines become spaces
This long sentence is wrapped in the file
but arrives as a single line of text.
 
defaults: &defaults # anchor
retries: 3
timeout: 30
 
staging:
<<: *defaults # alias, merges the anchor
url: https://staging.example.com

The pipe indicator keeps line breaks, which is what you want for shell scripts and embedded code. The greater than indicator folds wrapped lines into one paragraph, which is what you want for prose. Anchors and aliases let you define a block once and reuse it, and the merge key pulls those values into another mapping.

Where YAML Is Used

ToolFileWhy YAML
KubernetesManifests and Helm valuesDeeply nested specs that humans edit and review
Docker Composecompose.yamlService definitions with shared blocks via anchors
GitHub Actions.github/workflows/*.ymlMulti-line run steps benefit from block scalars
AnsiblePlaybooks and inventoriesReadable task lists that double as documentation
OpenAPIopenapi.yamlLarge specs where comments explain intent
Static site generatorsFront matter and configTerse metadata at the top of content files

Config work rarely stops at one format. Browse the full converter collection for YAML to JSON when a tool demands strict JSON, JSON to XML for older enterprise pipelines, and JSON Schema to validate the configuration you just wrote.

Standards and references

Frequently asked questions

How do I convert JSON to YAML?

Paste JSON, choose the YAML options and copy or download the output.

How are arrays represented in YAML?

Arrays use dash-prefixed sequence items; nested arrays are indented further.

Does YAML preserve JSON data types?

JSON values map naturally, but YAML parser versions can interpret unquoted scalars differently. Quote strings when in doubt.

What is the YAML 1.1 Norway problem?

YAML 1.1 can interpret the unquoted country code NO as false. Quoting it preserves a string.

Is conversion done locally?

Yes. Input conversion runs in the browser.