YAML to JSON: Convert Config Files When Your Code Needs JSON

PublishedToolYAML to JSON Converter

Contents
  1. Why YAML config gets blocked in code
  2. How to check: conversion rules and verification
  3. Common places people get stuck
  4. Wrapping up
  5. Frequently asked questions

Configuration files are often written in YAML. Structure is visible from indentation alone, and you can add comments freely, which makes YAML much easier for people to read and edit. But the moment you try to use those values inside JavaScript code or drop them straight into an API request body, you find out YAML won't work as-is.

Summary ① YAML is easy for people to read and write, but JavaScript objects and API request bodies expect JSON ② If you know the rules for moving from an indentation-based structure to a brace-and-bracket structure, you can convert it by hand ③ YAML with deep nesting or mixed lists is easy to get wrong by hand, so you need a step where you check the result with your own eyes

Why YAML config gets blocked in code

YAML represents hierarchy through indentation and puts values after a colon, which makes it easy to read. You can add comments (#) freely too, so it's widely used as a configuration file format.

The problem is that places like JavaScript's JSON.parse or a fetch request body don't understand YAML syntax. Those functions only parse JSON syntax: braces, brackets, and keys wrapped in double quotes.

So if you paste values from a config file straight into a test API request, or try to move them into frontend code as constants, you get a syntax error. The YAML itself is perfectly valid — it just fails anywhere JSON is expected.

How to check: conversion rules and verification

There are three rules when converting by hand. First, turn key: value into a form wrapped in double quotes. Second, wrap child items expressed by indentation in braces. Third, turn list items marked at the start of a line into bracket arrays.

YAML notationJSON notation
host: localhostKeys and values wrapped in double quotes
Child items grouped by indentationWrapped in braces
List items at the start of a lineConverted to bracket arrays
true, false, null, numbersKept as-is without quotes

The rules are simple, but once the hierarchy goes past two or three levels, matching up braces by hand isn't easy. If the structure has objects nested inside lists, the braces overlap and mistakes get even more likely.

Check it with our tool. Paste your YAML into the input box and the JSON result appears right below. Pick an indent width of 2 spaces, 4 spaces, or a single line (minified), then copy it and paste it into your code.

YAML to JSON Converter

Free · no sign-up · convert to JSON right in your browser

Common places people get stuck

SituationWhy it gets stuck
Structures with objects mixed into listsBraces inside brackets overlap, so matching them by hand is hard
Strings containing colons or quotesWithout escape handling, you get a syntax error
Indenting with a mix of tabs and spacesThe hierarchy is interpreted differently, so it converts into the wrong structure
Leaving a comma after the last itemJSON doesn't allow a trailing comma after the last item

The situations in this table don't jump out when you skim. You only see where the error is once you actually try to parse. Get in the habit of checking once after converting that the structure matches the original.

Wrapping up

YAML is a format that's easy for people to read and edit, and JSON is the format code and APIs understand. Turn colons into quotes, indentation into braces, and lists into brackets, and you can move it over by hand.

But when the hierarchy gets deep or lists and objects get mixed together, it's easy to slip up while matching braces. In that case, it's faster to use a tool that lets you verify the converted result right away.

YAML to JSON Converter

Free · no sign-up · convert to JSON right in your browser

Frequently asked questions

Can all YAML syntax be converted to JSON?

Structures commonly used in config files — key-value pairs, nested maps, and lists — can be carried over to JSON as-is. YAML-specific syntax like anchors and references, however, has no equivalent in JSON, so you need to expand the values first, then convert.

Can I use the converted JSON as-is in an API request body?

If it's been converted to a standard JSON structure, you can put it straight into the body of a fetch or axios request. Just check separately that the field names and value types the API expects match the keys in the original YAML.

Should I pick 2-space or 4-space indentation?

The parsed data itself is the same regardless of indent width. If you plan to paste it into a codebase you're collaborating on, match whatever spacing that project uses. For places where whitespace doesn't matter, like an API request body, the single-line (minified) option is handier.

This article was adapted from our Korean original. Read the Korean original

Related articles

  1. YAML indentation errors: find the line that breaks your CI deployOne wrong space in a GitHub Actions or GitLab CI YAML file can fail your deploy. Here's how indentation works and how to find the exact line.
  2. YouTube Auto-Generated Captions vs Manual Subtitles: SRT or VTT?YouTube's auto-generated captions misspell names and technical terms. Here's why manual subtitles are more accurate, and when to save SRT, VTT, or TXT.
  3. Add Line Numbers to Text: 5 Formats and Zero PaddingNumber every line of your text or code as 1., [1], 01., or (1) — plus how zero-padding width is calculated and how to skip blank lines.
  4. Anagram Checker: How to Tell If Two Phrases Are AnagramsLearn a 4-step manual way to check whether two words or phrases are anagrams, plus the hashing algorithm that makes the check instant.
  5. Profanity Filter Guide: Match Rules and Avoiding False PositivesLearn how profanity filters match words, why partial matching over-censors, and how to mask swear words without flagging normal text.
  6. Base32 Encoding Explained: 5-Bit Conversion, Padding, OTP KeysHow Base32 turns bytes into 5-bit chunks, why 0, 1, 8 and 9 never appear, how = padding works, and how to decode a Google Authenticator secret key.

Related tools