YAML Viewer
How It Works
- Step 1: Paste YAML configuration files from Kubernetes manifests, Docker Compose, Ansible playbooks, or CI/CD pipelines with nested structures and lists.
- Step 2: The viewer parses YAML using spec-compliant parsers, validating indentation (spaces only, no tabs), key-value syntax, and data type inference (strings, numbers, booleans, null).
- Step 3: Applies syntax highlighting with color-coded keys, values, comments, and anchors/aliases, making complex nested structures visually navigable.
- Step 4: Displays formatted YAML with proper indentation and optional JSON conversion, allowing easy inspection of configuration hierarchy and data relationships.
YAML Viewing Examples
Example: Kubernetes Config Visualization
apiVersion: v1
kind: Service
metadata:
name: my-service
spec:
selector:
app: MyApp
ports:
- protocol: TCP
port: 80
targetPort: 9376 apiVersion: v1 # API version (string)
kind: Service # Resource type (string)
metadata: # Metadata object
name: my-service # Service name (string)
spec: # Specification object
selector: # Label selector (object)
app: MyApp # App label (string)
ports: # Port list (array)
- protocol: TCP # Protocol (string)
port: 80 # External port (number)
targetPort: 9376 # Container port (number)
SYNTAX HIGHLIGHTING:
- Keys in blue: apiVersion, kind, metadata
- Strings in green: "v1", "Service", "my-service"
- Numbers in orange: 80, 9376
- Comments in gray: # annotations Key Changes:
The viewer formats Kubernetes YAML with proper 2-space indentation showing the hierarchical structure of API objects. Syntax highlighting distinguishes keys (apiVersion, kind) from values ('v1', 'Service'), making configuration structure immediately clear. The nested metadata and spec objects are visually indented to show parent-child relationships. Array items (ports list) are marked with hyphens and indented consistently. Data type inference is visible—port numbers (80, 9376) are recognized as integers, not strings. Comments can be added inline for documentation. This visualization is critical for debugging Kubernetes deployments where incorrect indentation or data types cause deployment failures. The viewer catches common errors like tabs instead of spaces, missing colons, or incorrect list syntax before applying configurations to clusters.
Frequently Asked Questions
How does the viewer handle YAML anchors, aliases, and merge keys?
The viewer fully supports YAML anchors (&anchor), aliases (*anchor), and merge keys (<<:) for DRY configuration. Anchors define reusable content: "defaults: &defaults" creates an anchor named "defaults". Aliases reference anchors: "production: *defaults" copies the defaults content. Merge keys combine mappings: "<<: *defaults" merges defaults into current mapping, allowing overrides. The viewer displays anchor definitions with a special marker and highlights alias references, showing the resolved content on hover. For example, "database: &db_config" followed by "staging: {<<: *db_config, host: staging.example.com}" merges db_config and overrides the host. This is essential for Kubernetes configs, Docker Compose files, and CI/CD pipelines (GitHub Actions, GitLab CI) where configuration reuse reduces duplication. The viewer validates that aliases reference existing anchors, preventing "unknown alias" errors at deployment time.
What YAML syntax errors does the viewer detect and how?
The viewer detects multiple syntax errors using a YAML 1.2 compliant parser: indentation errors (mixing spaces and tabs, inconsistent indentation levels), invalid characters in keys (unquoted keys with colons or brackets), unclosed quotes in string values, incorrect list syntax (missing dash or wrong indentation), mapping errors (duplicate keys, missing colons), and invalid escape sequences in strings. Error messages show the exact line number and column position with context: "Error at line 15, column 8: bad indentation of a mapping entry". The viewer highlights the problematic line in red and suggests fixes. For example, if you indent with 3 spaces when the file uses 2-space indentation, it warns "inconsistent indentation detected". This prevents deployment failures in Kubernetes where indentation errors cause pod creation failures or Ansible playbooks where syntax errors halt automation.
Can the viewer handle multi-line strings with different styles?
Yes. The viewer supports all YAML multi-line string styles: literal style (|) preserves line breaks and trailing newlines, folded style (>) folds newlines into spaces (except double newlines), literal chomping (|-) removes trailing newlines, literal keeping (|+) keeps all trailing newlines, and quoted strings with escaped newlines (\n). The viewer displays multi-line strings with proper formatting, showing whether line breaks are preserved or folded. For example, "description: |\n First line\n Second line" displays as a literal block with preserved indentation. This is critical for embedding scripts in Kubernetes ConfigMaps, Docker Compose environment variables, or Ansible playbook tasks where line break handling affects script execution. The viewer also handles edge cases like empty lines within multi-line strings and indentation within literal blocks.