YAML to JSON on Linux — Command Line vs Free Browser Method
- Four Linux methods: yq, Python one-liner, jq+Python combo, and browser tool.
- yq is the cleanest: brew install yq then yq -o=json eval file.yaml.
- Browser tool works on any Linux desktop with no install at all.
- Python method works everywhere Python is installed — no extra packages.
Table of Contents
On Linux you have four practical ways to convert YAML to JSON: the yq tool, a Python one-liner, a jq pipeline, or a browser-based converter that requires nothing installed. Which one is right depends on whether you need automation or just a fast one-off result.
The browser tool is the fastest for single files — open it in Firefox or Chromium on any Linux desktop, paste your YAML, get JSON in seconds. No package manager, no dependencies. For scripting or batch jobs, yq or Python is the right choice. This guide covers all four methods with copy-paste commands.
Method 1: yq — The Fastest CLI Method for YAML to JSON on Linux
yq is a lightweight YAML processor that reads, converts, and transforms YAML from the command line. It is the cleanest single-tool solution on Linux.
Install yq on Ubuntu/Debian:
sudo wget -qO /usr/local/bin/yq https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 sudo chmod +x /usr/local/bin/yq
Install yq on Fedora/RHEL:
sudo dnf install yq
Convert a YAML file to JSON:
yq -o=json eval input.yaml
Save output to a file:
yq -o=json eval input.yaml > output.json
Pretty-printed output:
yq -o=json --prettyPrint eval input.yaml
yq handles nested YAML, anchors, multiline strings, and complex Kubernetes manifests. It is the recommended method for scripting YAML-to-JSON pipelines on Linux.
Method 2: Python One-Liner — Works on Every Linux System
Python ships with most Linux distributions and can convert YAML to JSON with a two-line script. You only need to install the pyyaml package first:
pip install pyyaml
One-liner from the command line:
python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin.read()), indent=2))" < input.yaml
As a reusable script (yaml2json.py):
import yaml, json, sys data = yaml.safe_load(sys.stdin.read()) print(json.dumps(data, indent=2))
Then run:
python3 yaml2json.py < input.yaml > output.json
Batch convert all .yaml files in a directory:
for f in *.yaml; do
python3 yaml2json.py < "$f" > "${f%.yaml}.json"
done
The Python method is the most portable — it works on any Linux system with Python 3 installed, which is nearly all of them.
Sell Custom Apparel — We Handle Printing & Free ShippingMethod 3: jq Pipeline — If You Already Have jq Installed
jq is a JSON processor, not a YAML processor. But combined with a Python pre-step, you can chain them to convert YAML to JSON and then filter or reshape the output:
python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin)))" < input.yaml | jq '.'
This is useful when you need to extract specific values from a YAML file and output them as JSON. For example, get the image tag from a Kubernetes deployment YAML:
python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin)))" < deployment.yaml | jq '.spec.template.spec.containers[0].image'
Pure jq cannot read YAML directly — it requires JSON input. The Python step handles YAML parsing; jq handles filtering. If you only need the conversion (no filtering), yq is simpler.
Method 4: Free Browser Tool — No Install on Any Linux Desktop
If you are on a Linux desktop with Firefox or Chromium and do not want to install packages, the browser converter is the fastest option for one-off conversions.
Open the YAML to JSON converter in your browser. Paste your YAML and click Convert. The conversion runs inside your browser tab using standard browser technology — no server is contacted, no files are uploaded.
This method works on Ubuntu, Fedora, Debian, Arch, openSUSE, and any other Linux distribution with a modern browser. It is particularly useful when:
- You are on a restricted machine where you cannot install packages
- You need a visual result (you can see the YAML and JSON side by side)
- You want to quickly check whether your YAML is valid before using it in a script
- You need to convert a file once and have no use for a reusable script
For automation or batch processing, use yq or Python. For single conversions, the browser tool is faster than typing a command.
Which Linux Method to Use — Quick Decision Guide
| Situation | Best Method |
|---|---|
| Quick one-off on a desktop Linux | Browser tool |
| Shell script or CI/CD pipeline | yq |
| Python project, already using PyYAML | Python one-liner |
| Need to filter/transform the JSON output | Python + jq pipeline |
| Server with no GUI, no extra packages allowed | Python one-liner (Python 3 is pre-installed) |
All four methods produce identical output for the same YAML input. The choice is about environment and convenience, not result quality.
Convert YAML to JSON in Your Browser — No Install
Works on any Linux desktop in Firefox or Chromium. Paste YAML, click Convert, get JSON. No packages to install.
Open Free YAML to JSON ConverterFrequently Asked Questions
How do I convert YAML to JSON in the Linux terminal?
The cleanest terminal method is yq: install it with your package manager, then run yq -o=json eval input.yaml. If yq is not available, the Python one-liner works on any Linux system with Python 3 installed: python3 -c "import yaml,json,sys; print(json.dumps(yaml.safe_load(sys.stdin)))" < input.yaml
Can I convert YAML to JSON on Linux without installing anything?
Yes — either use the browser tool (open it in Firefox or Chromium on your Linux desktop, paste YAML, click Convert), or use the Python one-liner (Python 3 is pre-installed on most Linux distributions, and PyYAML installs with pip install pyyaml).
What is yq and how is it different from jq?
yq is a YAML processor that handles YAML natively. jq is a JSON processor — it requires JSON input. yq can read YAML and output JSON directly. jq requires a pre-conversion step (like a Python YAML parser) before it can process the data.
Does yaml to json conversion work the same on Ubuntu, Fedora, and Arch Linux?
Yes. YAML is plain text and the conversion logic is the same across all Linux distributions. The only difference is package manager syntax (apt vs dnf vs pacman) when installing yq. The Python one-liner and browser tool work identically on all distributions.

