YAML to JSON Converter

This YAML to JSON converter lets you switch between YAML and JSON formats instantly. Bidirectional with a lightweight browser-based parser.

This tool converts YAML to JSON and JSON to YAML in a split-pane interface. Paste YAML on the left and get formatted JSON on the right, or paste JSON and generate clean YAML. The built-in parser handles key-value pairs, nested objects, arrays, strings, numbers, booleans, and null values - enough for the vast majority of configuration files. Everything runs in your browser, so config files with secrets never leave your machine.

Ad
Ad

About YAML to JSON Converter

YAML vs JSON - When to Use Each

JSON is stricter and faster to parse, while YAML is more human-readable and supports comments. Pick JSON for machine-to-machine data exchange and YAML for config files that humans edit by hand.

Both YAML and JSON represent the same data structures (objects, arrays, strings, numbers, booleans, null), but they target different use cases.

FeatureYAMLJSON
ReadabilityVery high - minimal syntax noiseGood - but brackets and quotes add visual clutter
CommentsYes (# comments)No (not part of the spec)
Quoting stringsOptional for most stringsRequired for all strings and keys
Multi-line stringsBuilt-in (| and > blocks)No - must use \n escape sequences
Parsing speedSlower (indentation-based)Faster (simple grammar)
Language supportGood (libraries in all major languages)Universal (native in JavaScript, built-in in most languages)
Common useConfig files, CI/CD, Kubernetes, AnsibleAPIs, data exchange, package metadata

Where YAML Configuration Is Standard

Tool/PlatformConfig FileWhat It Configures
Docker Composedocker-compose.ymlMulti-container application stacks
Kubernetes*.yaml manifestsPods, deployments, services, ingresses
GitHub Actions.github/workflows/*.ymlCI/CD pipelines
GitLab CI.gitlab-ci.ymlCI/CD pipelines
Ansibleplaybooks/*.ymlServer provisioning and automation
Terraform*.tf (HCL, not YAML) but can use YAML for dataInfrastructure as code
Jekyll / HugoFront matter and _config.ymlStatic site generators
ESLint.eslintrc.ymlLinting rules (alternative to JSON/JS config)
Swagger/OpenAPIopenapi.yamlAPI specifications

YAML Syntax Quick Reference

YAML SyntaxJSON EquivalentNotes
key: value{"key": "value"}Basic key-value pair
parent:\n child: value{"parent": {"child": "value"}}Nesting via indentation (2 spaces typical)
- item1\n- item2["item1", "item2"]Array items prefixed with dash
count: 42{"count": 42}Numbers are auto-detected
active: true{"active": true}Booleans: true, false, yes, no, on, off
value: null{"value": null}Null: null, ~, or empty value
text: "hello: world"{"text": "hello: world"}Quote strings containing special characters
# comment(no equivalent)Comments are stripped during conversion

Common YAML Pitfalls

PitfallWhat HappensFix
Tabs for indentationYAML spec forbids tabs - parser errorUse spaces only (2 or 4 per level)
Norway problem: NO as valueYAML 1.1 interprets NO as boolean falseQuote it: "NO" or use YAML 1.2 parser
Unquoted colon in valuekey: value: more breaks parsingQuote the value: key: "value: more"
Inconsistent indentationChild misaligned with siblingsUse a consistent indent (2 spaces is standard)
Version string 1.0Parsed as number 1 (integer)Quote it: version: "1.0"
Trailing spacesCan cause unexpected multi-line valuesConfigure editor to strip trailing whitespace

The "Norway problem" is the most famous YAML gotcha. Country codes like NO, boolean-like strings like on/off/yes/no, and version numbers like 3.10 (parsed as 3.1) all need quoting. YAML 1.2 fixed the boolean problem by only recognizing true/false, but many parsers still use YAML 1.1 rules.

What This Parser Handles

FeatureSupportedNotes
Key-value pairsYesStandard scalar keys
Nested objectsYesVia indentation
Arrays (- syntax)YesSequence items
Strings (quoted/unquoted)YesSingle and double quotes
Numbers, booleans, nullYesAuto-detected types
Comments (#)YesStripped during conversion
Anchors and aliases (&/*)NoUse a full YAML library (js-yaml)
Multi-line strings (| and >)NoUse a full YAML library
Multi-document (---)NoSingle document only
Flow style ({key: val})NoUse block style instead

YAML Specification Versions

Most production YAML parsers target either the YAML 1.1 (2005) or YAML 1.2 (2009) specification, and the two differ in ways that bite real projects.

VersionReleasedKey Behaviour
YAML 1.0January 2004Original draft, largely of historical interest only
YAML 1.1January 2005Widely deployed for a decade. Treats yes/no/on/off as booleans. Source of the "Norway problem".
YAML 1.2October 2009Aligned with JSON as a strict superset. Only true/false are booleans. Cleaner type system.
YAML 1.2.2October 2021Editorial revision, no normative changes. Current reference spec.
YAML 1.3Under developmentAnnounced by yaml.io, still draft as of 2026

PyYAML, the most popular YAML library for Python, still defaulted to YAML 1.1 rules until PyYAML 6.0 shipped in October 2021. Ruby's Psych, Go's gopkg.in/yaml.v2, and many JavaScript parsers also shipped with 1.1 semantics for years. That is why boolean-like strings still cause surprise failures in 2026 config files that look perfectly valid.

Worked Example: Parsing a GitHub Actions Workflow

GitHub Actions workflows are a realistic test of a YAML to JSON converter. Here is a trimmed example and the JSON it produces.

YAML input:

name: CI
on:
  push:
    branches: [main]
jobs:
  test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - run: npm test

JSON output:

{
  "name": "CI",
  "on": {
    "push": {
      "branches": ["main"]
    }
  },
  "jobs": {
    "test": {
      "runs-on": "ubuntu-latest",
      "steps": [
        {"uses": "actions/checkout@v4"},
        {"run": "npm test"}
      ]
    }
  }
}

Note how the YAML "on" key becomes a string key in JSON. In YAML 1.1 parsers, unquoted "on" is interpreted as the boolean true, which is why GitHub Actions workflow validators complain about "true is not a valid event". The fix is quoting: "on":. This is the Norway problem in disguise.

Data Size and Performance

JSON is almost always smaller on the wire than equivalent YAML once you account for indentation. A 10,000-line Kubernetes manifest in YAML is typically 15-30% smaller when rendered as compact JSON, and 5-10% larger when rendered as pretty-printed JSON. Parsing speed also favours JSON by roughly an order of magnitude on most platforms because JSON has a simple context-free grammar while YAML requires tracking indentation state.

For developer-facing configs where file size and parse time do not matter, YAML's readability wins. For machine-to-machine APIs that run at scale, JSON wins. That is why Kubernetes accepts both formats at the API server but stores everything as JSON internally.

Common Conversion Gotchas

YAML-to-JSON round-tripping is not always lossless. The conversion strips comments, normalises whitespace, and loses the distinction between single-quoted, double-quoted, and plain scalars. If your YAML relies on anchors and aliases (for example a shared set of default values referenced across multiple services), the expanded JSON will contain the duplicated values - the reference structure is gone.

Watch for these specific cases when converting:

  • Numeric-looking strings: a key like version: 1.10 parses as the number 1.1 in most parsers. Quote it as "1.10" to preserve the trailing zero.
  • Leading zeros: code: 007 may be parsed as octal in YAML 1.1 (resulting in 7) but as the string "007" in YAML 1.2. Quote to be safe.
  • Timestamps: YAML 1.1 auto-parses ISO 8601 timestamps into datetime objects. JSON has no native date type, so the output is a string. Watch for timezone shifts in this conversion.
  • Very large numbers: JavaScript's JSON.parse loses precision beyond Number.MAX_SAFE_INTEGER (2^53 - 1). If your YAML has large IDs, treat them as strings on both sides.

The JSON Formatter is useful for inspecting the output and catching structural surprises. For the inverse problem of turning XML configs into JSON, the XML to JSON Converter handles that format, and the Base64 Encoder/Decoder is handy when your YAML contains encoded secrets you need to inspect.

Why YAML Dominates DevOps Config Files

Nearly every major DevOps and cloud-native tool released since 2014 has picked YAML as its default configuration format. Kubernetes manifests, Docker Compose files, GitHub Actions and GitLab CI pipelines, Ansible playbooks, Helm charts, and OpenAPI specifications are all YAML by default. The common thread is that these files are edited by humans in source control, reviewed in pull requests, and diffed line by line - situations where YAML's support for comments and minimal syntax pays off.

JSON, by contrast, dominates where the producer and consumer are both machines: REST and GraphQL API payloads, package metadata (package.json, composer.json), browser-to-server communication, and structured logging. When a human does need to read JSON, they usually run it through a formatter first, which is effectively admitting that raw JSON is hard to skim.

A useful rule of thumb: if humans write the file more often than machines read it, YAML is the better fit. If machines exchange the data more often than humans inspect it, JSON wins. Tools like Kubernetes that sit at the boundary accept YAML on input and serialise to JSON internally, which is exactly what this converter helps you inspect.

How the Built-In Parser Works

This converter ships with a lightweight YAML parser written in TypeScript that handles the subset of YAML used in roughly 95% of real-world config files. It tracks indentation depth to determine nesting, treats dash-prefixed lines as array items, auto-detects numbers and booleans by regex, and strips comment lines starting with #. Single-quoted and double-quoted strings are unwrapped, and the remaining scalars are treated as plain strings.

The parser deliberately does not support anchors, aliases, multi-document streams separated by ---, flow-style collections, or the various multi-line string indicators (| and > with chomp modifiers). If your file uses any of these features, the output may be wrong or the parser may refuse to continue. For full YAML 1.2 compliance, the js-yaml npm library is the standard JavaScript implementation, and PyYAML or ruamel.yaml are the standard choices in Python. For a browser-side conversion of a standard Kubernetes or Docker Compose file, the parser here is usually sufficient.

Sources

Frequently Asked Questions

What YAML features does this converter support?

The built-in parser handles the most commonly used YAML features including key-value pairs, nested objects via indentation, arrays using the dash prefix, strings (both quoted and unquoted), numbers, booleans (true/false), and null values. It covers the subset of YAML that appears in the vast majority of configuration files and data interchange scenarios.

Can I convert JSON back to YAML?

Yes. The tool is fully bidirectional. Paste JSON in the right pane and click "JSON to YAML" to get a YAML representation, or paste YAML in the left pane and click "YAML to JSON" to get formatted JSON output. Both directions produce clean, readable output.

Why use YAML instead of JSON?

YAML is often preferred for configuration files because it is more human-readable, supports comments, and requires less syntactic noise (no braces, brackets, or quotes for most values). JSON is better for data interchange between systems because it is stricter, more universally supported, and easier to parse programmatically. This tool lets you move freely between both formats.

Does this tool handle advanced YAML features like anchors or multi-line strings?

This tool uses a lightweight parser focused on the most common YAML patterns. Advanced features such as anchors, aliases, multi-document streams, and complex multi-line string styles are not supported. For files using these features, consider a full YAML library. For standard configuration files and data structures, this tool works well.

Link to this tool

Copy this HTML to link to this tool from your website or blog.

<a href="https://toolboxkit.io/tools/yaml-to-json/" title="YAML to JSON Converter - Free Online Tool">Try YAML to JSON Converter on ToolboxKit.io</a>