You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
yaml: add option for using Maps instead of objects for mappings #7283
Is your feature request related to a problem? Please describe.
JS objects are limited to string and symbol keys. If one needs different key types, there's Map.
YAML is capable of mappings that have non-string keys. It's a niche use case, sure, but one I have! I'm using number keys to map events that trigger at certain milestones in my data model:
milestones:
3: A36: D49: G3
Right now, I have to re-parse the numbers and convert it into a Map. An easy one-liner, but unnecessary IMO!
Another ugly use case that I don't personally have, but I guess is valid
I hope one never does this, but...
mapping:
2: technically"2": valid 😔
Describe the solution you'd like
Add a boolean option to ParseOptions, useMaps, defaulting to false.
Opened #7290 implementing this behind a useMaps boolean on the unstable parse(), per the request.
Two adjacent questions for maintainers that I deliberately kept out of that PR:
Stable stringify(new Map([["a", 1]])) silently emits {} today, which loses data. feat(yaml/unstable): add useMaps option to parse mappings into Maps #7290 fixes this only in the unstable stringify(). Should the stable one learn the same representation (a behavior change), or throw TypeError like other unrepresentable values do?
Longer term, for 2.0: should default object mode turn the "[object Object]" key coercion into a YamlSyntaxError that names useMaps, instead of silently mangling non-string keys?
Activity
tomas-zijdemans commentedon Aug 16, 2026
Opened #7290 implementing this behind a
useMapsboolean on the unstableparse(), per the request.Two adjacent questions for maintainers that I deliberately kept out of that PR:
stringify(new Map([["a", 1]]))silently emits{}today, which loses data. feat(yaml/unstable): add useMaps option to parse mappings into Maps #7290 fixes this only in the unstablestringify(). Should the stable one learn the same representation (a behavior change), or throwTypeErrorlike other unrepresentable values do?"[object Object]"key coercion into aYamlSyntaxErrorthat namesuseMaps, instead of silently mangling non-string keys?