TToolbox
≔

YAML to JSON

Convert between YAML and JSON

About this tool

YAML and JSON are the dual pillars of configuration and data serialization in modern cloud engineering. With indentation-driven semantics, YAML excels at human readability and is ubiquitous across Kubernetes manifests, Docker Compose, GitHub Actions, and Helm charts. Conversely, JSON is rigid and ideal for network transport. This tool provides bidirectional conversion between YAML and JSON with real-time syntax linting and anchor dereferencing.

How to Use This Tool (Step-by-Step)

1

Paste YAML or JSON Code

Paste your Kubernetes deployment manifest, docker-compose.yml, or JSON config into the input window.

2

Execute Bidirectional Conversion

Click 'YAML to JSON' or 'JSON to YAML' to parse the abstract syntax tree and restructure the output cleanly.

3

Review Syntax & Copy Output

Any indentation mismatches or syntax exceptions are flagged with exact line numbers. Copy validated code directly with one click.

YAML Anchors & Aliases Support

Handles YAML reusable anchors (&anchor) and alias references (*alias), automatically resolving and inlining nodes in JSON.

Accurate Indentation Diagnostics

Pinpoints exact line and column numbers on indentation mistakes and illegal tab characters, making config debugging painless.

100% Client-Side Confidentiality

Parsing executes entirely within local browser memory. Production Kubernetes secrets and deployment manifests remain completely private.

Strict YAML Syntax Rules & Common Gotchas

  • •Strictly NO Tabs: YAML forbids Tab characters for indentation. Use pure spaces exclusively (typically 2 spaces). Tabs cause immediate parsing errors.
  • •The Famous 'Norway Problem': In YAML 1.1, unquoted `NO`, `yes`, `on`, `off` parse as booleans. `country: NO` becomes `"country": false` in JSON! Always quote codes (`country: "NO"`).
  • •Colons and dashes mandate trailing spaces: Colons (`key: value`) and list dashes (`- item`) must be followed by a space. Writing `key:value` treats it as a single string literal.

Code & Transformation Examples

Docker Compose Configuration Conversion Benchmark

YAML Configuration
version: '3.8'
services:
  web:
    image: nginx:alpine
    ports:
      - "80:80"
    restart: always
Converted JSON Output
{
  "version": "3.8",
  "services": {
    "web": {
      "image": "nginx:alpine",
      "ports": [
        "80:80"
      ],
      "restart": "always"
    }
  }
}

* YAML minimizes syntactic noise for human editing; JSON provides strict boundaries for API consumers.

JavaScript YAML Parsing Snippet

Using js-yaml
import yaml from 'js-yaml';

// YAML 转 JSON 对象
const obj = yaml.load("name: Alice\nage: 30");
console.log(JSON.stringify(obj, null, 2));
Dumping Object to YAML
const data = { app: "toolbox", port: 3000 };
// 输出整洁缩进的 YAML 文本
const yamlStr = yaml.dump(data, { indent: 2 });
console.log(yamlStr);

* `yaml.load()` automatically parses types including booleans, integers, floats, and strings.

Frequently Asked Questions

Q: Can JSON be parsed directly as valid YAML?

A: Yes. From YAML 1.2 onwards, JSON is formally a valid subset of YAML. Any syntactically valid JSON file is natively valid YAML.

Q: How do I handle multiline text blocks in YAML?

A: Use the pipe `|` operator to preserve literal line breaks, or the folded `>` operator to collapse line feeds into single spaces for long paragraphs.

Q: Are there security risks with YAML parsing?

A: Backend libraries occasionally allow arbitrary object deserialization with raw `load()`. This tool uses strictly safe parsing with zero code execution vectors.

Related Tools

All processing happens locally in your browser. Your data is never uploaded to a server.
/