ModernCalcs

YAML to JSON Converter

{
  "name": "my-app",
  "version": "2.1.0",
  "debug": false,
  "port": 8080,
  "database": {
    "host": "localhost",
    "port": 5432,
    "name": "myapp_db",
    "credentials": {
      "user": "admin",
      "password": "s3cr3t"
    },
    "pool": {
      "min": 2,
      "max": 10
    }
  },
  "features": [
    "authentication",
    "authorization",
    "rate-limiting"
  ],
  "servers": [
    {
      "name": "primary",
      "host": "10.0.0.1",
      "port": 8080,
      "active": true
    },
    {
      "name": "secondary",
      "host": "10.0.0.2",
      "port": 8080,
      "active": false
    }
  ],
  "logging": {
    "level": "info",
    "outputs": [
      "stdout",
      "/var/log/app.log"
    ]
  }
}

Supports: mappings, sequences, nested objects, block scalars (| and >), type coercion (null, bool, number). Comments (#) are stripped. Anchors/aliases and complex keys are not supported.

YAML to JSON: Convert Kubernetes, Docker, and GitHub Actions Config

YAML is everywhere in modern DevOps: Kubernetes manifests, Docker Compose files, GitHub Actions workflows, and application configs. Converting YAML to JSON lets you work with these files in JavaScript, feed them to REST APIs, or validate them with JSON Schema. Paste your YAML and get well-formatted JSON instantly.

Formula
# YAML database: host: localhost port: 5432 features: - auth - logging // JSON output { "database": { "host": "localhost", "port": 5432 }, "features": ["auth", "logging"] }

Unquoted numbers, booleans, and null are automatically typed. Quote values to force string type.

YAML's Whitespace-Sensitive Structure

YAML uses indentation (spaces only, not tabs) to define structure. A key followed by indented lines creates a nested object. Lines starting with - create array items. Consistent indentation is critical — an off-by-one indent error changes which object a property belongs to. The converter uses the indent level of each line to determine its nesting depth.

Type Coercion Rules

YAML automatically infers types. Unquoted 'true'/'yes'/'on' → boolean true; 'false'/'no'/'off' → boolean false; 'null'/'~' or empty → null; integers (42) and floats (3.14) → JSON numbers. To prevent coercion, quote the value: '"true"' stays as the string true. This is important for values like version numbers ('1.0' should be a string, not a number).

Block Scalars for Multi-line Strings

| (literal block scalar) preserves newlines in multi-line strings — use for code snippets, SQL queries, or shell scripts embedded in YAML. > (folded block scalar) folds newlines into spaces — use for long descriptions that are broken across lines for readability but should be one paragraph in the output.

Practical Examples

Converting a Kubernetes Manifest to JSON

Process a Kubernetes YAML manifest in a JavaScript tool that only accepts JSON.

  • 1.Paste the Kubernetes YAML (Deployment, Service, ConfigMap, etc.)
  • 2.Review the JSON output — spec, metadata, and containers are nested correctly
  • 3.Use the JSON in your tooling, REST call, or JSON Schema validator
  • 4.Convert back with a JSON-to-YAML tool if needed for kubectl apply

Extracting Values from a GitHub Actions Workflow

Parse a GitHub Actions workflow YAML to inspect jobs and steps.

  • 1.Paste the .github/workflows/*.yml content
  • 2.The jobs map and steps arrays become JSON objects and arrays
  • 3.Inspect the JSON to find specific step names, environment variables, or conditions
  • 4.Use jq or JavaScript to query the resulting JSON structure

YAML Patterns Supported

  • Mappings: key: value → JSON object properties
  • Sequences: - item → JSON array elements
  • Nested: indented blocks → nested JSON objects/arrays
  • Block scalars: | (literal) and > (folded) multi-line strings
  • Type coercion: null, booleans, numbers auto-detected

Good Use Cases

  • Converting Kubernetes manifests for REST API calls
  • Parsing Docker Compose files in JavaScript tooling
  • Reading GitHub Actions workflows programmatically
  • Validating YAML configs against JSON Schema definitions

Frequently Asked Questions

What YAML features are supported?

Mappings (key: value), sequences (- item), nested objects, block scalars (| for literal, > for folded), type coercion (null/~, true/false/yes/no, numbers), quoted strings, inline arrays and objects, and document markers (---). Anchors (&), aliases (*), merge keys (<<), and multi-document streams are not supported.

How does YAML type coercion work?

YAML automatically converts unquoted values to types. 'true', 'yes', 'on' → JSON true; 'false', 'no', 'off' → JSON false; 'null', '~' → JSON null; numeric values → JSON numbers. To keep a value as a string, quote it: '"123"' stays as the string '123' rather than the number 123.

What is the Norway problem?

The Norway problem is a famous YAML gotcha: 'NO' parses as boolean false in YAML 1.1, so a list of country codes would wrongly convert Norway's 'NO' to false. YAML 1.2 fixed this (only 'true'/'false' are booleans), but many parsers still use YAML 1.1 semantics. This converter uses 'yes'/'no'/'on'/'off' as YAML 1.1 does.

What is the difference between | and > block scalars?

| (literal block scalar) preserves newlines — each line in the block becomes a line in the string. > (folded block scalar) folds newlines into spaces, treating the block as a single paragraph. Both strip leading indentation. Use | for code snippets and > for prose descriptions.