mirror of
https://github.com/nlohmann/json.git
synced 2026-03-04 16:26:26 +00:00
extended "add" to cope with arrays
This commit is contained in:
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")
|
||||
{
|
||||
|
||||
@@ -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")
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user