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

JSON into std::tuple #339

Closed
ibitton opened this issue Oct 20, 2016 · 2 comments
Closed

JSON into std::tuple #339

ibitton opened this issue Oct 20, 2016 · 2 comments

Comments

@ibitton
Copy link

ibitton commented Oct 20, 2016

I've visited previous issues mentioning tuple/user-defined types/etc and I thought it would be awesome if I could do something like this:
json myJSON;
myJSON["stringKey"] = "stringVal";
myJSON["intKey"] = 5;
myJSON["customKey"] = myCustomObj; //this is not really needed for my use case
auto myTuple = myJSON.get<tuple<string, int, MyType /* again, not super necessary */>();
I'm not 100% sure this is the right way about it, but I think my objective is clear: have a way to store/retrieve (serialize/deserialize) a dictionary/map with custom types and then get those types back automagically.

@nlohmann
Copy link
Owner

The problem is that a tuple is ordered whereas a JSON object is not. Hence, a mapping between the values stored in the JSON object and the types in the tuple is arbitrary.

@ibitton
Copy link
Author

ibitton commented Oct 20, 2016

I see. Thanks for clearing that up.

@ibitton ibitton closed this as completed Oct 20, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants