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

Idea: Handle Multimaps Better #816

Closed
Exaeta opened this issue Nov 3, 2017 · 8 comments
Closed

Idea: Handle Multimaps Better #816

Exaeta opened this issue Nov 3, 2017 · 8 comments
Labels
kind: enhancement/improvement state: please discuss please discuss the issue or vote for your favorite option state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated

Comments

@Exaeta
Copy link

Exaeta commented Nov 3, 2017

My understanding is that currently:

std::multimap<std::string,  std::string> a = { {"a", "1"}, {"a", "2"}, {"b", "3"} };

Might map to:
{ "a": "1", "b": "3" }

But this does not preserve equality of the conversion back and forth. Thus I suggest a different way to convert multi-maps:
{ "a": ["1", "2"], "b": ["3"] }
This preserves equality.

@nlohmann
Copy link
Owner

nlohmann commented Nov 4, 2017

Interesting idea. I would like to discuss this.

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Nov 4, 2017
@Exaeta
Copy link
Author

Exaeta commented Nov 23, 2017

@nlohmann It seems that the actual behavior differs from the documented behavior, at least in the case of std::map. I'm not sure what exactly it's doing now for multimap, but I suppose figuring that out and updating the documentation would be a good thing.

@nlohmann
Copy link
Owner

@Exaeta What do you mean?

@nlohmann
Copy link
Owner

Coming back to your original idea about multisets: How would we translate back from JSON to multisets?

Would we require the same structure; that is, would { "a": ["1", "2"], "b": ["3"] } be convertible whereas { "a": "1", "b": "3" } would not?

@nlohmann
Copy link
Owner

nlohmann commented Dec 6, 2017

Any opinions on this?

@stale
Copy link

stale bot commented Jan 5, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated label Jan 5, 2018
@stale stale bot closed this as completed Jan 13, 2018
@luxe
Copy link
Contributor

luxe commented Apr 22, 2021

I found this behavior surprising because it loses data. I'm going to convert my multimaps into map<T,vector<V>> for serializing

@nlohmann
Copy link
Owner

It's surely a corner-case for which an implementation must make a decision as there is no canonic representation here. Any proposal how to improve the documentation to avoid surprises?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: enhancement/improvement state: please discuss please discuss the issue or vote for your favorite option state: stale the issue has not been updated in a while and will be closed automatically soon unless it is updated
Projects
None yet
Development

No branches or pull requests

3 participants