// yaml

YAML Statistics.

Inspect a YAML document: total keys, max depth, counts of strings, numbers, booleans, arrays, and objects.

Client-sideCountsNo upload

YAML input

Statistics

Why inspect YAML structure?

When working with large YAML files — Kubernetes manifests with dozens of resources, CI/CD pipelines with many jobs, or application configs with deep nesting — understanding the structure at a glance saves time. This tool gives you a quick summary: how many keys exist, how deep the nesting goes, and what types of values are present.

The statistics update live as you type, so you can see how changes affect the structure. Add a new key and watch the total count increase. Nest an object deeper and see the max depth grow. It's a quick way to validate that your YAML has the shape you expect.

What each metric means.

Total keys counts every mapping key at every level of nesting. A flat object with 5 keys has totalKeys = 5; a nested object with 3 top-level keys each containing 2 sub-keys has totalKeys = 9. Max depth measures the deepest nesting level — a flat object has depth 1, one level of nesting gives depth 2, and so on.

Strings, numbers, booleans, nulls count leaf values by type. Arrays counts sequence nodes. Objects counts mapping nodes. These counts help you understand what kind of data your YAML contains without reading the entire document.

Use cases.

Config validation. If you expect a Kubernetes manifest to have exactly 4 resources but the stats show only 3 objects, you know something is missing. If max depth is higher than expected, you may have accidental nesting.

API response analysis. When debugging an API that returns YAML, paste the response here to see its structure instantly. Check if the expected fields are present and whether the nesting matches your schema.

Performance profiling. Very deep nesting (depth > 8) can cause issues with some YAML parsers and config management tools. Use this tool to check depth before passing large configs to third-party services.

Understanding nesting depth.

Nesting depth measures how many levels deep your YAML structure goes. A flat object like { name: "api" } has depth 1. Adding a nested object like { service: { name: "api" } } increases the depth to 2. Most YAML parsers handle moderate nesting well, but depth beyond 8 or 10 can cause stack overflow errors in recursive parsers or performance degradation in tools that traverse the entire tree.

If you see an unexpectedly high max depth, check for accidental nesting — a common mistake is indenting a value too far and creating an unintended nested object. The statistics tool makes this visible immediately without reading the entire document line by line.

Using statistics for documentation.

When documenting a YAML-based API or configuration format, the statistics give you a quick summary to include in your docs. "This manifest contains 47 keys across 8 objects with a maximum nesting depth of 4" is a useful reference point for developers who need to understand the structure before reading the full specification.

You can also use statistics to compare two versions of a config file. If version 1 has 30 keys and version 2 has 35, you know five keys were added. If max depth increased from 3 to 5, you know the structure became more complex. This kind of high-level comparison helps during code reviews where reading every line isn't practical.

Type distribution and data modeling.

The breakdown of strings, numbers, booleans, and nulls tells you about the nature of your data. A config file that's mostly strings might benefit from type coercion — converting port numbers from "5432" to 5432. A file with many booleans might indicate feature flags or configuration toggles that could be managed more systematically.

Arrays in YAML represent lists of items. A high array count relative to total keys suggests a configuration dominated by lists — common in CI/CD pipelines with many steps or Kubernetes manifests with multiple resources. Understanding this distribution helps you decide whether to split large files into smaller, more focused ones.

FAQ

How do I count how many keys/values are in a YAML file?

Parse with PyYAML and walk the dict: `len(list(yaml.safe_load(open(f)).keys()))` for top-level, or recurse for nested; a stats tool will show total/unique keys, depth, file size.

How can I find duplicate keys in a YAML file?

Parse with `yaml.safe_load_all` and count key occurrences, or use `yamllint` with the `key-duplicates` rule enabled — duplicated keys silently override each other in most parsers.

What's the deepest nesting level in my YAML config?

Write a recursive function that tracks max dict depth, or use a YAML stats analyzer that reports tree depth alongside key/value counts.

How do I see which keys are most common across my YAML files?

Use `yq` to extract keys across files and `sort | uniq -c | sort -rn` for frequency, or load all into Python and count key occurrences with a defaultdict.

Is there a YAML linter that reports file metrics?

`yamllint` reports document count and warns on structural issues; for raw stats (lines, keys, bytes, depth), use `cloc` for code stats or a dedicated YAML analyzer.