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.

821<23sp ansty="le--0:#D6DEEB;--1:#403F">53<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dnumeric k1<1"d ivclassNa="meco">48tr53<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dboolean k1<1"d ivclassNa="meco">48nu53<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dnull k1<1"d ivclassNa="meco">5<3[sp ansty="le--0:#F78C6C;--1:#AA09">8<21sp ansty="le--0:#D6DEEB;--1:#403F">53<, sp ansty="le--0:#F78C6C;--1:#AA09">8<22sp ansty="le--0:#D6DEEB;--1:#403F">53]<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Darray k1<1"d ivclassNa="meco">53<{ sp ansty="le--0:#7FDBCA;--1:#1111">1<1asp ansty="le--0:#D6DEEB;--1:#403F">53<: sp ansty="le--0:#ECC48D;--1:#3B61">B<0bsp ansty="le--0:#D6DEEB;--1:#403F">53 }<: sp ansty="le--0:#D9F5DD;--1:#1111">1<1"sp ansty="le--0:#ECC48D;--1:#984E">4Dobject k1<1"d ivclassNa="meco">
1<111" spans="tyle--0:#ECC48D;--1:#98">4E41<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53: spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dquoted numeric st1<111 "divclass="Name"><"di vdivclass="Nameexpressive-">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4D1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53: spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dquoted boolean st1<111 "divclass="Name"><"di vdivclass="Nameexpressive-">11113F<53: spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dstring< key spans="tyle--0:#D9F5DD;--1:#11">1<111 "divclass="Name"><"di vdivclass="Nameexpressive-">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dkey with sp1<111" spans="tyle--0:#D6DEEB;--1:#40">3F<53: spans="tyle--0:#D9F5DD;--1:#11">1<111" spans="tyle--0:#ECC48D;--1:#98">4E4Dquoted st1<111 "divclass="Name">

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.