Guides
How to convert YAML to JSON: the quick answer and three methods
Paste it into a browser tool, run yq in a terminal, or parse it in code, depending on the job.
How to convert YAML to JSON, in one line: paste the YAML into a browser converter such as AyeTab and copy the JSON it prints. If you are in a terminal, run yq -o json file.yaml; in code, parse with a YAML library and serialize with a JSON one. The rest of this page explains each route and which to choose.
Method 1: in the browser (fastest for one file)
- Open the AyeTab YAML to JSON page.
- Paste your YAML into the pane marked YAML.
- The JSON pane fills in. Press its copy button.
Nothing to install and no account to make. AyeTab parses the text inside your own browser, so the file is not uploaded, and the page carries on working without a connection once it has loaded. It also converts the other way: paste JSON and you get YAML back.
Method 2: on the command line (best for repeat jobs)
yq is a free command-line YAML processor, distributed as one Go binary. After installing it:
yq -o json config.yaml > config.json
It copes with files holding more than one YAML document and accepts jq-style expressions, so you can pick out one key while converting. Use this route for build scripts, CI jobs or a folder full of files. Here it is the better choice over any web page.
Method 3: in code (when your program needs the data)
Every mainstream language has a YAML parser. Two common ones:
| Language | Read YAML | Write JSON |
|---|---|---|
| Python | PyYAML yaml.safe_load(f) |
json.dumps(data) |
| JavaScript | js-yaml load(text) |
JSON.stringify(data) |
In Python, prefer safe_load; PyYAML recommends it for any input you do not trust.
Which method should you use?
- You have one file open right now: the browser.
- The conversion runs every time you build or deploy: yq.
- You need to check or reshape the values first: code.
Check the result before you use it
The conversion is mechanical, but YAML has habits that change your data on the way:
- Comments vanish. JSON has no comment syntax, so any
#notes are gone. - Some words become true or false. Under YAML 1.1 rules, unquoted
yes,no,onandoffare booleans. Put quotes around them if you meant text. - Indentation sets nesting. A key indented one space too far lands inside the wrong object, and the JSON braces make that easy to spot.
A quick look at the JSON output answers most "why is my config wrong" questions, because the structure is spelled out instead of implied by spaces.
Getting the converter one keystroke away
AyeTab also ships as a free Chrome extension. It swaps your new tab for a developer toolbox, adds a side panel, and opens a command palette on Ctrl+K or Cmd+K, so you can type "yaml" and land on the converter. Smart paste goes a step further and suggests a tool when you paste something in.
FAQ
What is the easiest way to convert YAML to JSON? Paste it into a browser converter like AyeTab and copy the output. It takes seconds and needs no install.
How do I convert YAML to JSON in the terminal?
Install yq and run yq -o json file.yaml.
Can I convert YAML to JSON offline? Yes. yq runs locally, and AyeTab keeps working in the browser once its page has loaded.