Skip to content

yaml: add option for using Maps instead of objects for mappings #7283

Description

@KevinMGranger

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: A3
  6: D4
  9: 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.

Describe alternatives you've considered

Just putting up with converting the objects 🤷

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions