Skip to content

stringMappingKeys

Enforces mapping keys to be strings.

✅ This rule is included in the yaml logical and logicalStrict presets.

YAML allows mapping keys of any type, including numbers, booleans, arrays, and objects. However, most programming languages and data interchange formats expect mapping keys to be strings. Non-string keys can cause interoperability issues, parsing failures, or unexpected type coercion when YAML documents are processed by different tools.

This rule reports on mapping keys that aren’t strings.

123: "numeric key"
true: "boolean key"
null: "null key"
[1, 2]: "array key"
{ a: b }: "object key"

This rule is not configurable.

If your YAML documents are only consumed by tools that support non-string keys and you intentionally use typed keys for semantic purposes, you may not need this rule. Some specialized YAML use cases, such as configuration files for specific frameworks, may rely on non-string keys.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.