Skip to content

How do I get an array of structs from a json object? #2270

Answered by nlohmann
m4l490n asked this question in Q&A
Discussion options

You must be logged in to vote

First, the library will not be able to create a C-style array for you. You will only be able to retrieve a std::vector, though. For this, you need to "unpack" the JSON array from the JSON object like this:

auto JSON = result["array"].get<std::vector<my_struct_t>>();

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@m4l490n
Comment options

@nlohmann
Comment options

Answer selected by nlohmann
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants