JSON and YAML represent the same underlying data model: objects, arrays, strings, numbers, booleans, and nulls. What differs is the syntax. JSON is compact and strict — every key must be quoted, every value delimited precisely. YAML is human-friendly and flexible — indentation carries meaning, comments are allowed, and strings often need no quotes at all. The two formats are commonly used side by side in a single project, which means conversion between them comes up regularly.
DevToolShack has both directions covered: the JSON to YAML converter and the YAML to JSON converter. Both run entirely in your browser. Here is what to know about how the conversion works and where to watch for surprises.
How JSON Maps to YAML
The data types map cleanly in both directions. Understanding the mapping makes it easier to predict what the output will look like and to spot problems when values don't convert as expected.
Objects
// JSON
{ "name": "Alice", "role": "admin" }
# YAML
name: Alice
role: admin
JSON object keys lose their quotes in YAML. Values that are unambiguous — simple strings, numbers, booleans — also lose their quotes. The curly brace wrapping disappears entirely, replaced by indentation.
Arrays
// JSON
{ "tags": ["developer", "reviewer", "admin"] }
# YAML
tags:
- developer
- reviewer
- admin
JSON arrays become YAML block sequences: each item on its own line, prefixed with a hyphen and a space. Inline flow sequences ([developer, reviewer]) are also valid YAML but less common in config files.
Nested objects
// JSON
{
"user": {
"name": "Alice",
"address": { "city": "Austin", "state": "TX" }
}
}
# YAML
user:
name: Alice
address:
city: Austin
state: TX
Nesting is expressed through indentation in YAML rather than through curly braces. Each level adds two spaces (the standard, though four spaces and tabs are also valid in YAML — just not mixed within a file).
Booleans and null
// JSON
{ "active": true, "deleted": false, "notes": null }
# YAML
active: true
deleted: false
notes: null
These convert directly. However, YAML has a broader set of values it treats as booleans than JSON does. In YAML 1.1 (still used by some tools), yes, no, on, and off are booleans. YAML 1.2 removed these, so if you're converting YAML to JSON and your YAML uses yes or no, verify which YAML version your parser targets. The post on YAML vs JSON covers this gotcha and others in depth.
What YAML Has That JSON Doesn't
The JSON-to-YAML direction is always lossless: every valid JSON document converts to valid YAML that represents the same data. The YAML-to-JSON direction can lose information, because YAML supports features JSON doesn't.
Comments. YAML allows comments with #. JSON has no comment syntax. When converting YAML to JSON, all comments are stripped. If you're converting a hand-written YAML config to JSON to pass to an API, your documentation disappears.
Multi-line strings. YAML's literal block scalar (|) and folded block scalar (>) let you write multi-line strings cleanly. These convert to a single JSON string with embedded newlines, which is valid JSON but less readable.
Anchors and aliases. YAML lets you define a value once with an anchor (&anchor) and reuse it elsewhere with an alias (*anchor). Converters expand these before producing JSON, which can lead to repeated content in the output. The YAML deduplication is lost.
Multiple documents. A single YAML file can contain multiple documents separated by ---. JSON has no equivalent. Converters typically only handle the first document or produce an array of JSON objects.
Common Conversion Scenarios
Copying a JSON API response into a GitHub Actions workflow. GitHub Actions uses YAML. If you have a JSON object you want to use as a config value in a workflow, converting it to YAML first saves manually reformatting the structure.
Moving a Kubernetes manifest between tools. Some Kubernetes tools and dashboards export configuration as JSON; others expect YAML. The converter bridges the gap without requiring kubectl or yq.
Converting an OpenAPI specification. OpenAPI specs exist in both JSON and YAML forms. Teams often prefer YAML for hand-editing (comments, readability) and JSON for API consumption. Both formats are spec-equivalent.
Debugging a YAML config. YAML syntax errors are sometimes hard to read. Converting to JSON and running it through the JSON Formatter can make the structure clearer and help isolate where the YAML went wrong.
Converting in Code
For automation, Python's pyyaml library handles both directions cleanly:
import json, yaml
# JSON to YAML
with open('config.json') as f:
data = json.load(f)
with open('config.yaml', 'w') as f:
yaml.dump(data, f, default_flow_style=False, allow_unicode=True)
# YAML to JSON
with open('config.yaml') as f:
data = yaml.safe_load(f)
with open('config.json', 'w') as f:
json.dump(data, f, indent=2)
In Node.js, the js-yaml package is the standard choice. For command-line conversion without writing a script, yq is a powerful YAML processor that also handles JSON and is worth adding to your toolkit if you work with configuration files regularly.
yaml.load() in PyYAML can execute arbitrary Python code embedded in YAML input. yaml.safe_load() restricts parsing to safe types only. This matters whenever the YAML comes from an untrusted source.For one-off conversions without installing anything, the JSON to YAML and YAML to JSON tools on DevToolShack are the fastest option. Paste your input, get your output, copy and move on.