extended "add" to cope with arrays
This commit is contained in:
parent
397ada22d3
commit
855cf2307b
3 changed files with 65 additions and 3 deletions
src
20
src/json.hpp
20
src/json.hpp
|
@ -9560,7 +9560,25 @@ basic_json_parser_63:
|
|||
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")
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue