-
-
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
Insertion into nested json field #621
Labels
Comments
What would be |
This works, but may not be what you want: #include "json.hpp"
using json = nlohmann::json;
int main()
{
std::vector<std::string> strings = {"one", "two", "three"};
json j;
for (auto& i : strings) {
j["Outer level"]["Inner level[i]"][i] = i;
}
std::cout << j << std::endl;
} |
match would be a string, for example, std:string match = "Hello";. Thanks! |
And what is |
int ii = 0;
for (auto& i : strings) {
if (std::regex_match(i, match, rgx)) {
std::ssub_match submatch = match[1];
j["includes"][ii] = submatch.str();
std::cout << submatch.str() << '\n';
ii++;
}
} This works perfectly, thank you! |
Thanks for checking back! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Suppose one wants to insert iteratively into a nested field, for example:
pushback() does not do this and one cannot use a string type as index, i.e, j["Outer Level"][str] doesn't work - is there any way to do this?
Many thanks!
The text was updated successfully, but these errors were encountered: