HomeJSON ConvertersYAML to JSON Converter

YAML to JSON Converter

Convert, prettify, and parse YAML documents into clean, structured JSON format instantly. Features include anchor/alias expansion, multi-document parsing strategies, alphabetic key sorting, and custom indentation options.

Convert, prettify, and parse YAML documents into clean, structured JSON format instantly. Features include anchor/alias expansion, multi-document parsing strategies, alphabetic key sorting, and custom indentation options.

This tool is designed to provide a seamless experience for developers by handling complex operations directly in your browser with maximum speed and security.

100% Private
Instant Results
Customizable
Offline Ready
Dev-Friendly
Easy Export

YAML and JSON represent the same underlying data model — objects, arrays, strings, numbers, booleans, and null — but in different syntactic forms. YAML uses indentation and human-readable conventions; JSON uses explicit delimiters (braces, brackets, commas) and mandatory quoting. YAML is a superset of JSON, meaning every JSON document is valid YAML, but the reverse is not true — YAML documents with comments, anchors, aliases, and block scalars cannot be directly read by a JSON parser. YAML to JSON conversion is the process of parsing YAML, resolving its features (anchors, aliases, type coercion), and serializing the resulting data as JSON.

The distinction matters most in automated systems. A Kubernetes YAML manifest, a Helm chart values file, a GitHub Actions workflow, an Ansible playbook — these are human-written YAML. But the systems that process them work internally in JSON: the Kubernetes API server stores and communicates resource state as JSON, kubectl converts YAML manifests to JSON before sending them to the API, Helm templates produce JSON output, Terraform's data sources return JSON. When you need to inspect, process, query with jq, pipe to another tool, or pass to an API that accepts only JSON, you need the YAML converted to JSON first.

YAML has additional features that affect conversion behavior. Anchors (&anchor) define a named block of YAML, and aliases (*anchor) reference that block elsewhere in the same document — it is YAML's way of avoiding repetition. A Docker Compose file that uses extension fields with anchors to share service configuration between multiple services is valid YAML but not directly parseable as JSON — the anchor references must be resolved to their actual values before JSON serialization. The converter handles this automatically. YAML also coerces types from string values — the unquoted value true becomes boolean true, 42 becomes integer, 3.14 becomes float. The JSON output reflects the types that the YAML parser resolved, not the raw string values in the YAML source.

Read the Full Guide

Paste any YAML into the input field and click Generate JSON Data. The tool parses the YAML using a standards-compliant YAML parser, resolves all anchors and aliases to their actual values, applies YAML's type coercion rules (unquoted true and false become JSON booleans, unquoted numbers become JSON numbers, ~ and null become JSON null), and serializes the result as formatted JSON with consistent 2-space indentation and sorted keys. YAML anchors and aliases are fully resolved in the output. If your YAML defines a service configuration as an anchor (&defaults) and then references it in multiple places (*defaults), the JSON output will have the fully expanded values at each reference point — JSON has no equivalent of YAML anchors, so the content must be duplicated. Multi-document YAML files (documents separated by ---) are converted to a JSON array where each element is the parsed content of one document. This handles Kubernetes manifest bundles where multiple resources are defined in a single YAML file separated by ---. The generated JSON can be used immediately with tools that require JSON input: jq queries work on JSON, not YAML — running cat config.yaml | yaml2json | jq '.services.web.image' extracts a value from a YAML file using jq. REST APIs accept JSON request bodies where some configuration originates from YAML files. Terraform's external data source requires JSON. AWS CloudFormation can accept JSON equivalents of what are often YAML templates. The converter's output is the bridge between the YAML you write for human readability and the JSON that automated systems need to process.

1. Paste your YAML into the Input YAML field — paste any valid YAML: a Kubernetes manifest, a Docker Compose file, a Helm values.yaml, an Ansible variable file, a GitHub Actions workflow excerpt, or any other YAML content. The tool accepts single-document YAML and multi-document YAML (multiple documents separated by ---). Click Load Example to see a sample YAML with nested objects and arrays before using your own content.

2. Click Generate JSON Data — the tool parses the YAML, resolves all anchors and aliases to their concrete values, applies type coercion (unquoted true/false become booleans, unquoted numbers become numbers, null and ~ become JSON null), and outputs the equivalent JSON formatted with 2-space indentation in the result panel. For multi-document YAML, the output is a JSON array with one element per document.

3. Review the JSON output — verify that the structure matches what you expected. Check nested objects to ensure indentation-dependent nesting was parsed correctly. If you had anchors in the YAML, confirm the aliased values are correctly expanded at each reference point in the JSON. If a YAML comment was followed by a colon, verify it was not misinterpreted as a mapping key.

4. Use the JSON output in your target system — copy it and paste it as a REST API request body, pipe it to jq (save to a file first: cat output.json | jq '.fieldName'), use it as Terraform input data, or use it as the comparison baseline when inspecting kubectl get -o json output. The formatted JSON is immediately usable without any additional processing.

5. For command-line workflows, note that this browser tool is convenient for manual inspection and one-off conversions. For automated pipelines, use yq (the command-line YAML processor that supports YAML to JSON conversion: yq -o=json input.yaml), or a short Python script: python3 -c "import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))" < input.yaml.

jq is the answer to a lot of YAML problems, except jq only processes JSON. The number of times I have wanted to run a jq query against a Kubernetes manifest, a Docker Compose file, or a GitHub Actions workflow file — and had to first find or write a YAML-to-JSON step — is substantial. jq '.spec.template.spec.containers[0].image' will tell you the container image in a Deployment manifest, but only after the YAML has been converted to JSON. kubectl get deployment my-app -o json | jq does this automatically because kubectl outputs JSON, but for local YAML files, you need the conversion step. This tool is that step, done in a browser without installing yq or writing a Python one-liner. Debugging Kubernetes configuration problems is another constant use case. When something goes wrong with a Kubernetes resource, kubectl describe shows a human-readable summary but kubectl get -o json shows the full resource state including fields that describe does not surface. If you started with a YAML manifest and want to understand how Kubernetes interpreted it — what the actual resource JSON looks like after the API server processed it — kubectl get -o json gives you the JSON state, and comparing it to your original YAML converted to JSON helps you spot discrepancies between what you wrote and what Kubernetes stored. For Helm chart development, the conversion direction is often from values YAML to JSON for inspection. Helm's --dry-run outputs the final rendered YAML templates, and converting that output to JSON makes it much easier to inspect specific values with jq, validate the structure programmatically, or pipe it to another tool in a CI pipeline. The same applies to Ansible's variable files (group_vars, host_vars) that are written in YAML — converting them to JSON for processing in a script or for passing to a tool that expects JSON is a frequent task in mixed-automation environments.

Anchor and alias resolution — YAML anchors and aliases are fully expanded in the JSON output since JSON has no equivalent of anchors and all referenced values must be present at each location

Multi-document support — YAML files with multiple documents separated by --- are converted to a JSON array with one element per document enabling conversion of Kubernetes manifest bundles

Type-aware conversion — YAML type coercion is applied correctly: unquoted booleans become JSON booleans unquoted numbers become JSON numbers null and ~ become JSON null and quoted values stay as JSON strings

Pretty-printed output — the JSON output uses consistent 2-space indentation making it immediately readable and usable in documentation API testing tools and configuration files

Handles complex YAML features — block scalars (| and >) are correctly parsed to their string values and included in the JSON output as quoted string values

100% browser-based — your YAML content including Kubernetes secrets Helm values with credentials and Ansible vault-adjacent data never leaves your machine

No installation required — convert YAML to JSON immediately in the browser without installing yq python-yaml or any other command-line tool

Instant for any size — parsing and conversion runs locally in your browser with results appearing immediately for YAML files of any size

Converting Kubernetes YAML manifests to JSON for processing with jq to extract specific field values

Converting Docker Compose YAML files to JSON for inspection or for comparison with Docker API JSON output

Converting Helm values.yaml files to JSON for use in CI pipelines that require JSON configuration inputs

Converting Ansible variable files (group_vars host_vars) to JSON for use in scripts or tools that expect JSON

Converting GitHub Actions workflow YAML to JSON for programmatic analysis or for feeding to a workflow validation tool

Converting YAML configuration files to JSON for use as Terraform external data source inputs

Resolving YAML files with anchors and aliases to their fully expanded JSON equivalent for debugging configuration inheritance

Inspecting the fully parsed representation of YAML files that use complex anchors to understand the final resolved configuration

Example Input

id: 1
name: Priya Singh
email: priya@learnhubly.com
isActive: true
score: 98.5
tags:
  - developer
  - admin
profile:
  bio: Principal Software Engineer
  skills:
    - Go
    - React
    - TypeScript
deletedAt: null

Example Output

{
  "id": 1,
  "name": "Priya Singh",
  "email": "priya@learnhubly.com",
  "isActive": true,
  "score": 98.5,
  "tags": [
    "developer",
    "admin"
  ],
  "profile": {
    "bio": "Principal Software Engineer",
    "skills": [
      "Go",
      "React",
      "TypeScript"
    ]
  },
  "deletedAt": null
}

Indentation Issues — Tab Characters Instead of Spaces: YAML requires spaces for indentation — tab characters are explicitly forbidden by the YAML specification. A file that appears correctly indented in a text editor that renders tabs as spaces will fail to parse when the actual tab characters are detected. If the converter reports an indentation error, check the source file for tab characters: in most code editors, show invisible characters or use a linter to detect tabs. Replace all tab indentation with spaces (2-space indentation is the most common convention for YAML).

Colon in Unquoted String Value Parsed as Mapping: In YAML, a colon followed by a space ('key: value') is the mapping separator. If a value contains a colon and space — a URL like https://example.com or an error message like 'Error: connection refused' — without quotes, the YAML parser may misinterpret the content after the colon as a nested value or throw a parse error. If conversion fails on a YAML that contains URLs or messages, identify the lines with bare colons in values and add quotes around those string values.

Invalid YAML Syntax From Manual Editing: YAML written by hand — or copied from documentation that used proportional fonts, or edited in a rich text editor that substituted typographic quotes — often contains syntax errors that a YAML parser rejects but that appear correct to the eye. Common issues: inconsistent indentation levels (some blocks indented 2 spaces, others 4), duplicate keys in the same mapping (YAML parsers vary in how they handle this — some take the last value, some error), and escaped characters that are not valid in YAML contexts. Use the YAML Formatter/Validator tool first to identify and fix syntax errors before converting.

YAML Comments Lost in JSON Output: YAML supports comments starting with #. JSON has no comment syntax. All comments in the YAML input are dropped during conversion — they cannot be represented in JSON. This is expected behavior, not an error. If your YAML has important comments that should be preserved, note them separately before converting. After converting and using the JSON, the original YAML with its comments remains the authoritative human-readable source.

Anchors Referencing Earlier Aliases Resolving to Unexpected Values: YAML anchors must be defined before the aliases that reference them. An alias (*anchor) that appears before its anchor definition (&anchor) in the file is invalid and will cause a parse error. If the converter reports an undefined alias error, find the alias reference in your YAML and verify the anchor definition appears earlier in the file. Also check that anchor names match exactly — YAML anchor names are case-sensitive.

Expecting YAML boolean shortcuts (yes/no, on/off) to convert to JSON booleans

Fix: In YAML 1.1, the values yes, no, on, off, and their capitalization variants (Yes, YES, No, NO, On, OFF) were converted to boolean true and false. In YAML 1.2 (the current standard), only true and false are recognized as booleans. The parser used by this tool follows YAML 1.2 conventions, so yes and no remain strings in the JSON output — they do not become true and false. If your YAML uses yes/no for booleans (common in Ansible, which uses a YAML 1.1-based parser), the JSON output will have string values 'yes' and 'no' rather than booleans. Either update the YAML to use true/false, or be aware that downstream JSON consumers will receive string values.

Converting a Kubernetes Secret YAML to JSON and then storing or transmitting the result

Fix: Kubernetes Secrets store sensitive data (passwords, tokens, TLS certificates) base64-encoded in the data field. The YAML representation looks like data: password: dGhpcyBpcyBhIHNlY3JldA==. Converting this to JSON gives you the same base64-encoded values. The values are not decrypted or decoded by the conversion — they are still base64 and still sensitive. Be careful about where you paste, save, or transmit the converted JSON. A Secret's JSON representation is just as sensitive as the YAML. For inspecting the actual decoded secret values, use kubectl get secret my-secret -o jsonpath='{.data.password}' | base64 --decode rather than converting and inspecting the full YAML.

Using the JSON output directly in a Kubernetes API call without understanding the full resource structure

Fix: A Kubernetes YAML manifest converted to JSON gives you the JSON equivalent of the manifest. But submitting a JSON body to the Kubernetes API requires understanding which endpoint accepts which resource and which fields are server-managed vs user-provided. The API server expects resources at specific endpoints (POST /apis/apps/v1/namespaces/default/deployments for a Deployment), and the full resource JSON must include apiVersion, kind, and metadata. kubectl handles all of this for you automatically. If you are calling the Kubernetes API directly with curl or an HTTP client, the converted JSON from this tool is the body — but you still need to construct the correct URL, authentication headers, and ensure you are posting to the right endpoint for the resource type.

Assuming jq can process YAML directly without conversion

Fix: jq is a JSON processor — it only accepts JSON input. Piping a YAML file directly to jq will produce a parse error because jq cannot parse YAML syntax. To use jq with a YAML file, convert first: either use this browser tool to convert and save the JSON, or use a command-line approach: yq -o=json input.yaml | jq '.fieldName' (yq converts to JSON and pipes to jq), or cat input.yaml | python3 -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin)))' | jq '.fieldName'. The YAML to JSON conversion step is the prerequisite for any jq-based YAML processing.

Editing the JSON output and expecting those changes to be reflected back in the original YAML

Fix: The JSON output is a snapshot of the YAML data at the time of conversion. Editing the JSON does not update the original YAML — they are separate documents. If you need to make changes and round-trip back to YAML, make the changes in the JSON, then convert the JSON back to YAML using the JSON to YAML converter, then verify the resulting YAML is correctly structured. For configuration files that need to stay in YAML (Kubernetes manifests, Helm values), always make changes to the YAML source, not to a temporary JSON conversion. Use the JSON conversion for inspection and processing, not as an edit target.

Does it handle YAML anchors?

Yes. YAML anchors (&name) and aliases (*name) are fully resolved during conversion. An anchor defines a named block of YAML content, and each alias is a reference to that block. In the JSON output, every alias is replaced with the actual content of the anchor at that position — JSON has no equivalent of references or reuse, so the content must be fully duplicated at each reference point. If a Docker Compose file uses anchor-based extension fields to share configuration between services, the JSON output will have the complete configuration at each service rather than the anchor reference. This makes the JSON larger than the YAML but fully self-contained.

What happens to YAML comments during conversion?

All comments are dropped. JSON has no comment syntax, so YAML comments — which start with # and can appear on their own line or at the end of a line — have no representation in JSON. This is expected and unavoidable, not a limitation of this tool specifically. If you are converting YAML that has important comments (explaining why a value is set, documenting version requirements, noting TODOs), save the original YAML file as your source of truth and add corresponding documentation to wherever the JSON is used.

Does it support multi-document YAML files?

Yes. YAML files can contain multiple documents separated by --- (three dashes on their own line). Kubernetes manifest bundles often use this pattern — a single .yaml file with a Deployment and a Service separated by ---. The converter processes each document and outputs a JSON array where each element is the parsed content of one document. If the YAML has a single document (no --- separator), the output is a single JSON object or array, not wrapped in an outer array.

Why does YAML type conversion matter for the JSON output?

YAML automatically converts unquoted scalar values to their inferred types. The unquoted value true becomes boolean true, 42 becomes integer, 3.14 becomes float, and null or ~ become JSON null. These are reflected in the JSON output — the JSON will have boolean true rather than the string 'true', integer 42 rather than '42'. This is usually what you want, but it can be surprising when a YAML value like a version string '1.0' is stored unquoted (1.0) and becomes a float in JSON rather than the string '1.0'. Quote values in YAML that should remain strings regardless of whether they look like numbers or booleans.

How do I convert YAML to JSON in the command line without a browser?

Several options. With yq (the YAML command-line processor): yq -o=json input.yaml > output.json. With Python (built-in yaml and json modules): python3 -c 'import sys, yaml, json; print(json.dumps(yaml.safe_load(sys.stdin), indent=2))' < input.yaml. With Ruby: ruby -ryaml -rjson -e 'puts JSON.pretty_generate(YAML.safe_load(STDIN))' < input.yaml. With Node.js and the js-yaml package: node -e "const yaml=require('js-yaml');const fs=require('fs');console.log(JSON.stringify(yaml.load(fs.readFileSync('/dev/stdin','utf8')),null,2))". For one-off conversions in the browser, this tool is faster. For automated pipelines and scripting, the command-line approach is more appropriate.

Can I convert a Kubernetes manifest bundle with multiple resources to JSON?

Yes — a Kubernetes manifest file with multiple resources separated by --- (Deployment + Service + ConfigMap in one file) produces a JSON array with three elements, one per resource. Each element is the full JSON representation of one Kubernetes resource including apiVersion, kind, metadata, and spec. This JSON array can be used with tools that process JSON arrays, or you can extract individual resources with jq: jq '.[0]' bundle.json for the first resource, jq '.[] | select(.kind == "Deployment")' bundle.json to extract only the Deployment resource by kind.

Is the JSON output minified or pretty-printed?

The output is pretty-printed with 2-space indentation by default, making it immediately readable. Pretty-printed JSON is what you want for pasting into documentation, reading in a text editor, or copying into a REST API client like Postman that renders JSON. If you need minified JSON (no whitespace, single line) for embedding in a curl command or for a system that does not handle formatted JSON well, copy the output and run it through a JSON minifier, or use the JSON Formatter tool to toggle between formatted and minified output.

Why would I use YAML to JSON instead of just working with YAML directly?

A few concrete reasons. jq only processes JSON — if you want to query YAML data with jq, you must convert first. REST APIs accept JSON request bodies, not YAML — if your configuration source is YAML and you need to post it to an API, convert first. Terraform's external data source outputs JSON and expects JSON — integrating YAML-sourced data requires conversion. Programmatic comparison of two configurations is easier in JSON where you can use JSON diff tools rather than YAML diff tools that have to account for semantically equivalent but syntactically different representations. And inspecting what Kubernetes actually stored for a resource (kubectl get -o json) gives JSON — comparing it to your YAML manifest converted to JSON reveals configuration drift clearly.