-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
Parsing JSON Array where members have no key, using custom types #1267
Comments
Thanks for providing such a detailed issue. I tried to reproduce it, but had some strange observation:
This is really strange, and I fear the only person who can help here would be @theodelrieu. |
@theodelrieu Do you have any idea on this? |
I'm not sure I understand the exact issue, it seems to me that you could do the following: void from_json(json const& j, PublicKey& k) {
podFromHex(k.data, j.get<std::string>());
} Have I missed something? |
Also, note that you must have |
Thank you, that worked! I was not aware I could just get the raw string from the json, I figured I needed a way to index it as it was all one large object. |
I'm trying to reduce the level of nesting in my output JSON. I can do this fine by converting my type directly to a string, rather than giving the single member variable a name, for example:
instead of
This works fine, and in my usage this function gets used to convert a std::unordered_set to json. Here's an example json output I get:
Now however, I'm not sure how to convert this JSON back into my type. The type is a std::unordered_set. Previously, I was giving a data name to each array element, so my from_json looked like -
However, this cannot work if we are not storing the key name. How can we implement our from_json function without having a key name to at()?
What is the expected behavior?
Am able to convert json to custom type
And what is the actual behavior instead?
Which compiler and operating system are you using? Is it a supported compiler?
Compiler: g++ 8.2.1
OS: Linux 4.18.9
Did you use a released version of the library or the version from the
develop
branch?Using the released version, v3.2.0
If you experience a compilation error: can you compile and run the unit tests?
N/A
edit - Of course I could just use a function and loop through the data, but I'd prefer a solution where I don't need to have a function for each standard container type which already has support built in
The text was updated successfully, but these errors were encountered: