FormatterHQ

YAML to JSON Converter

Convert YAML config, manifests and fixtures into JSON. Anchors are expanded, types are resolved the YAML 1.2 way, and errors show the exact line and column.

Input YAML
Output JSON
Ready.

How to use the YAML to JSON Converter

  1. Paste YAML into the input editor, upload a .yaml/.yml file, use Load URL, or click Sample.
  2. Choose the JSON Indent (2, 3, 4 spaces or tab) and tick Sort keys if you want alphabetical keys.
  3. Click Convert to JSON; the status bar shows the record count or an error with its line and column.
  4. Copy the JSON or Download it.

Convert YAML to JSON for tools that only speak JSON

YAML is the format people prefer to write, and JSON is the format most APIs, databases and libraries accept. This YAML to JSON converter parses your document and writes the same data as JSON, so you can send a Kubernetes manifest to an API, load an OpenAPI description into a tool that wants JSON, or turn YAML test fixtures into request bodies.

Example

server:
  host: 0.0.0.0
  port: 8080
  debug: off
allowed: [web, api]
motd: |
  Welcome
  back
timeout: 30s

Converted with a 2-space indent:

{
  "server": {
    "host": "0.0.0.0",
    "port": 8080,
    "debug": "off"
  },
  "allowed": [
    "web",
    "api"
  ],
  "motd": "Welcome\nback\n",
  "timeout": "30s"
}

Three details are worth noticing: port became a number, debug: off stayed the string "off", and the literal block | kept its line breaks, including the final newline, as \n escapes.

How YAML structures map to JSON

YAMLJSON
mapping (key: value)object
sequence (- item or [a, b])array
true, falseboolean
~, null, empty valuenull
block scalars | and >string with \n or folded spaces
anchors &x and aliases *xthe value copied at every alias
several documents separated by ---an array of documents

Comments are not part of the data, so they do not appear in the JSON.

The Sort keys option is handy when you compare two YAML files that list the same settings in a different order: convert both with sorting on and the JSON versions line up key for key. Leave it off when the order carries meaning for people reading the output, as in an OpenAPI document.

Type surprises to check before you rely on the output

This converter follows the YAML 1.2 core schema. That avoids some classic YAML 1.1 traps but not all of them:

  • yes, no, on and off stay strings. A YAML 1.1 tool would read them as booleans, so if the file is shared with such tools, prefer true/false.
  • Unquoted 1.10 is the number 1.1, and 007 is 7. Quote version numbers, zip codes and IDs.
  • Dates such as 2024-05-01 are kept as strings, because JSON has no date type.
  • .inf and .nan have no JSON representation and are written as null.
  • Merge keys (<<: *base) are not merged; they appear as a literal "<<" property.

Common conversion errors

  • Tabs in indentation – replace them with spaces.
  • A colon inside an unquoted value, such as title: Step 1: install – wrap the value in quotes.
  • Duplicate keys in one mapping – YAML forbids them and the converter reports the line.

If you are not sure where the problem is, the YAML validator gives the same messages while you edit.

Going the other way

To turn JSON back into YAML, use the JSON to YAML converter. Comments and the original layout cannot be recovered after a round trip, so keep the YAML as your source file. When you need the result in other shapes, the YAML converter offers XML, CSV, TOML and HTML from the same input.

Privacy

Parsing and conversion run in your browser, so your YAML is not uploaded. Load URL fetches files through our server and Save & Share stores the content for a link, only if you use them.

Convert YAML to JSON in Python

PyYAML reads the document and the standard json module writes it. Two defaults trip people up. PyYAML turns an unquoted date such as 2024-05-01 into a datetime.date, which json.dumps() rejects with TypeError: Object of type date is not JSON serializable; default=str writes it as a string instead. And json.dumps() escapes non-ASCII characters, giving caf\u00e9, unless you pass ensure_ascii=False.

# pip install pyyaml
import json
import yaml

text = """
server:
  host: 0.0.0.0
  port: 8080
released: 2024-05-01
motd: café
"""

data = yaml.safe_load(text)
print(json.dumps(data, indent=2, ensure_ascii=False, default=str))

For this sample the script and the converter above produce the same JSON, so the page is a quick way to see what a file should convert to before you automate it.

Frequently asked questions

How do I convert a Kubernetes YAML with several resources to JSON?
Paste the whole file. Documents separated by --- become elements of a JSON array, one per resource, in the order they appear.
Why did "on: yes" not become a boolean?
The converter follows YAML 1.2, where only true and false are booleans. YAML 1.1 tools treat yes/no/on/off as booleans. Use true and false to be unambiguous.
Are YAML comments kept in the JSON?
No. JSON has no comment syntax, and comments are not part of the parsed data.
Why is my version number 1.10 shown as 1.1?
Unquoted, it is parsed as a floating-point number. Quote it in the YAML ("1.10") to keep it as a string in the JSON.
Can I convert OpenAPI or Swagger YAML to JSON?
Yes. An OpenAPI document is ordinary YAML, so it converts to the equivalent JSON document that JSON-only tools can load.

Last updated October 3, 2026

Guides

Related tools