How to Convert YAML to JSON on Mac

Photo of Simon Simon Guide 5 min read

YAML and JSON show up everywhere in modern development. Your CI pipeline is probably YAML. Your Kubernetes manifests are YAML. Your app config might be YAML. But the API you are testing speaks JSON, your logs are JSON, and most tooling expects JSON.

So you end up needing to move data between the two formats constantly: paste a YAML config, get JSON out, tweak it, and sometimes convert it back.

This guide explains how YAML and JSON relate to each other, when you need to convert between them, and how to do it quickly and locally on macOS.

YAML vs. JSON: What’s the Difference?

YAML and JSON describe the same kind of data: objects, arrays, strings, numbers, and booleans. In fact, every valid JSON document is also valid YAML. The difference is mostly about how the data looks and who is meant to read it.

JSON uses braces, brackets, and quotes:

{
"service": "api",
"port": 8080,
"replicas": 3,
"tags": ["web", "public"]
}

YAML uses indentation and is designed to be easier for people to read and write by hand:

service: api
port: 8080
replicas: 3
tags:
- web
- public

Both describe exactly the same data. YAML tends to win for configuration that humans edit often, while JSON tends to win for data that machines exchange.

When You Need to Convert

A few common situations:

  • You have a YAML config and need JSON to paste into an API request or test fixture.
  • You copied a JSON response and want readable YAML for a config file.
  • You are debugging a CI or Kubernetes file and want to see its JSON shape.
  • A tool only accepts one format and your data is in the other.

The conversion itself is simple. The annoying part is doing it dozens of times a day without breaking your flow.

Option 1: Convert in Terminal

macOS does not ship with a dedicated YAML converter, but if you have Python 3 installed (it comes with the Xcode Command Line Tools), you can convert in one line.

YAML to JSON:

Terminal window
python3 -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin)))' < config.yaml

JSON to YAML:

Terminal window
python3 -c 'import sys, yaml, json; print(yaml.safe_dump(json.load(sys.stdin)))' < data.json

The yaml module is not part of the standard library, so you may first need to install it:

Terminal window
pip3 install pyyaml

If you prefer a dedicated tool, yq works well too:

Terminal window
# Convert YAML to JSON
yq -o=json '.' config.yaml
# Convert JSON to YAML
yq -P '.' data.json

Terminal is great if you already have these tools installed and you are comfortable on the command line. The downside is the setup, remembering the exact flags, and that it does not help much when you want to read, tweak, and re-convert the result interactively.

Option 2: Use an Online Converter

There are plenty of websites that convert YAML to JSON. You paste your data in one box and copy the result from another.

For a quick, throwaway snippet, that is fine. The problems are familiar: you have to leave your editor, search for a converter, pick a random result, and deal with whatever ad-heavy, cookie-banner-covered page you land on.

There is also the data question. CI files, Kubernetes manifests, and app configs often contain hostnames, internal service names, environment details, or secrets. Pasting them into a random website is not something you want to do by habit, even if the conversion itself is harmless.

Option 3: Use DevKnife’s Converter

DevKnife includes a Converter tool that transforms data between JSON, YAML, TOML, XML, and CSV right on your Mac. You paste your YAML or open a file, pick the output format, and the JSON appears instantly in the other panel. Switch the dropdowns and it converts back the other way just as fast.

DevKnife Converter converting YAML to JSON

DevKnife’s Converter transforms YAML to JSON locally on your Mac.

You can get data into the tool a few ways:

  • Type or paste directly into the input panel.
  • Open a file from disk using the toolbar.

Once the data is loaded, choose the input and output formats from the dropdowns and the converted result appears automatically. You can then save the output straight to disk without copying it between apps.

Because DevKnife runs natively on macOS, the conversion happens locally. That matters for CI configs, manifests, and anything with internal details, but the everyday win is simpler: no search results, no noisy converter pages, and no browser detour for a small task.

A Quick Rule of Thumb

Reach for Terminal when you are already scripting and the tools are installed. Reach for an online converter only for small, non-sensitive snippets when you do not have anything else handy. For everyday back-and-forth between YAML and JSON, a fast local tool keeps the task where it belongs: next to your code.

Conclusion

YAML and JSON are two views of the same data, and developers move between them all day. Terminal can handle the conversion with Python or yq, and online tools work for quick public snippets. For routine work, DevKnife’s Converter gives you instant YAML-to-JSON conversion (and back) without leaving your Mac or your editor flow.

Tweet Share

Further Reading

·
Guide

How to Open JSON Files on Mac

Learn how to open JSON files on your Mac using built-in tools, online viewers, browser extensions, and dedicated apps like DevKnife.

Read More
·
Guide

The Easiest Way to Compare Text on macOS

A simple guide to comparing text on macOS without relying on the command line or heavy IDEs. Learn lightweight ways to spot differences quickly and clearly.

Read More
DevKnige logo

Ready to try DevKnife?

Fast, private, and built for macOS.

Made for Apple Silicon · macOS 14 · Just 10 MB