1
0
mirror of https://github.com/nlohmann/json.git synced 2025-07-13 20:21:48 +03:00

extended "add" to cope with arrays

This commit is contained in:
Niels
2016-04-24 16:51:06 +02:00
parent 397ada22d3
commit 855cf2307b
3 changed files with 65 additions and 3 deletions

View File

@ -8870,7 +8870,25 @@ class basic_json
throw std::domain_error("'add' operation must have member 'value'");
}
result[ptr] = it_value->second;
const auto last_path = ptr.pop_back();
basic_json& parent = result.at(ptr);
if (parent.is_object())
{
parent[last_path] = it_value->second;
}
else if (parent.is_array())
{
if (last_path == "-")
{
parent.push_back(it_value->second);
}
else
{
parent.insert(parent.begin() + std::stoi(last_path),
it_value->second);
}
}
}
else if (op == "remove")
{