// text
Extract YAML Keys.
Get a complete list of every key in a YAML document, with full dotted paths, and a tree view.
YAML input
Keys
Extracting YAML keys.
This tool parses your YAML and lists every key path as a dot-separated string. For example, database.primary.host shows the full path from root to leaf. Nested keys include their parent path; array indices are not included in the key paths (arrays don't have named keys).
The output is one key per line, sorted alphabetically. This gives you a quick overview of the YAML structure without reading the entire document. It's especially useful for large config files with dozens or hundreds of keys.
Use cases.
Schema validation. Compare extracted keys against an expected schema to verify your YAML has all required fields. If a key is missing, the YAML is incomplete. If an unexpected key appears, there may be a typo.
Documentation. Use the key list as a starting point for documenting a config file. Each key path can be annotated with a description, creating a complete reference.
Migration. When migrating a config from one format to another (YAML to JSON, YAML to environment variables), the key list tells you exactly what needs to be converted. Use it as a checklist.
Output format.
Keys are output as dot-separated paths: service.name, database.primary.host, feature_flags.experimental. This format is compatible with JavaScript object access (config.service.name) and environment variable naming conventions (SERVICE_NAME).
Array elements don't have meaningful keys, so they appear as their parent path. The tool focuses on mapping keys (object properties), not array indices. This approach gives you a clean, focused view of the configuration structure without the noise of array position indicators.
Advanced use cases.
Environment variable mapping. Convert dot-separated keys to environment variable names by uppercasing and replacing dots with underscores. For example, database.primary.host becomes DATABASE_PRIMARY_HOST. This is essential for Docker Compose and Kubernetes deployments where configuration is injected via environment variables.
Access control. Use the extracted key list to define per-key access policies. Grant read access to database.* keys for operations teams while restricting service.api_key to deployment pipelines only.
Diff and comparison. Extract keys from two versions of a YAML file and compare the lists to see exactly which configuration options were added, removed, or renamed between versions. This is invaluable for reviewing configuration changes in version control.
Auto-generated documentation. Feed the key list into a documentation generator that produces a structured reference for your configuration file. Each key path becomes a section heading, and you fill in descriptions for what each setting controls.
Configuration auditing. Compare the extracted keys against a known baseline to detect configuration drift. When multiple environments share a base config, extracting keys from each variant reveals which overrides have been added or removed, helping maintain consistency across staging and production. This approach is particularly useful for teams managing multiple deployment environments with shared configuration templates.
Tooling integration. The flat key list can be piped into form generators, config editors, or IDE plugins that auto-complete YAML keys. By pre-extracting the keys, you eliminate the need for the tool to parse the full YAML document on every keystroke, improving editor responsiveness for large files.
FAQ
How do I list all keys in a YAML file from the command line?
`yq '. | keys' file.yaml` lists top-level keys; `yq '.. | keys? // empty' file.yaml` recursively gets all keys including nested ones.
How do I extract specific YAML keys matching a pattern?
`yq '.[] | select(.name | test("^prod-"))' file.yaml` filters by regex; combine with `select` for type-based extraction.
Can I get all keys at a specific nesting level in YAML?
Yes — `yq '.level1 | keys' file.yaml` gets keys under `level1`; for arbitrary depth use a path expression like `.a.b.c | keys`.
How do I extract keys and their values from YAML into CSV?
`yq -o=csv '.[] | {"key": .name, "value": .value}' file.yaml` outputs a CSV with key and value columns ready for spreadsheets.
How to count how many times each key appears in YAML?
`yq '.. | objects | keys | .[]' file.yaml | sort | uniq -c | sort -rn` gives a frequency count of all keys across the document.