Closed seivan closed 8 years ago
Per Yaml spec, order of mappings should not be preserved. In Yaml, !!map
is the default tag for mappings and it is explicitly specified that order of keys need not be maintained. On the other hand, there is a `!!omap`` tag which specifies that order of keys should be maintained and it is a sequence.
You can maintain order of keys by using a sequence of compact mappings like this:
- key1: value1
- key2: value2
Yeah but it would be good if you could specify OrderedDictionaries to keep a one to one mapping of the textual representation. Right now, can’t ensure that a key has been read in to the system as order is not preserved. JSON has the same problem, so it makes sense since it’s a superset.
But I am wondering if it’s a purely implementation detail? Why does it matter for the user that the keys are not in order?
On 2016Oct04, at 10:00, Behrang Noruzi Niya notifications@github.com wrote:
Per Yaml spec, order of mappings should not be preserved. In Yaml, !!map is the default tag for mappings and it is explicitly specified that order of keys need not be maintained. On the other hand, there is a !!omap` tag which specifies that order of keys should be maintained and it is a sequence.
You can maintain order of keys by using a sequence of compact mappings like this:
- key1: value1
- key2: value2 — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/behrang/YamlSwift/issues/39#issuecomment-251320293, or mute the thread https://github.com/notifications/unsubscribe-auth/AADYgP5cx_uQf5ghfZiFv2Atnxtkbd27ks5qwgeXgaJpZM4KNQzv.
I don't get the problem. I don't understand your point in:
can’t ensure that a key has been read in to the system as order is not preserved
It is specified that the user should not rely on order of keys.
Yeah but from my point of view, that seems like an implementation detail. But you're right, since the specification say so, it's probably better not move forward with this.
It would be great if we could keep the order of the keys as the same as the source file parsed from. I know JSON doesn't maintain order, but it could be useful in scenarios where YAML is used for configurations and we need access to defined variables within the YAML tree.