Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature request] Ordered mapping keys #52

Open
agladysh opened this issue Jan 15, 2023 · 1 comment
Open

[feature request] Ordered mapping keys #52

agladysh opened this issue Jan 15, 2023 · 1 comment

Comments

@agladysh
Copy link

I would like to order mapping keys in the dump for human readability.

For my use case a flat list is enough.

How about something like this?

yaml.dump(data, { mapping_key_order = { "key1", "key2", ... } }) -- keys not in the list are dumped in the end

and, for finer control:

yaml.dump(data, { mapping_key_order = function(mapping) -- This may be the default if mapping_key_order = true
   local keys = tkeys(mapping)
   table.sort(keys)
   return keys
end }) -- keys not in the list are dumped in the end

If mapping_key_order is not specified, use the current implementation for performance.

@agladysh
Copy link
Author

The simplest solution would probably be to allow user to supply alternative pairs() implementation to be used in the dump_mapping here:

https://github.com/gvvaughan/lyaml/blob/master/lib/lyaml/init.lua#L124

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant