[Solved]: Dictionary with empty key in YAML

Problem Statement:

I would like to know if I can create a map in YAML with Empty KEY.

e.g. map: { somedifficultString: "someEasyString", empty key: "none" }

basically, I would like to display “none” if the input key is “empty string”


Solution:

you can use ~ for representing null value in YAML.

YAML

map: { somedifficultString: "someEasyString", ~: "none" }

JSON

{ "map": { "somedifficultString": "someEasyString", "": "none" }}

Basic Example:

YAML

~: "none:

Corresponding JSON output:

{ "": "none"}


Reference: https://stackoverflow.com/questions/40248327/dictionary-with-empty-key. I have answered there also you can check.