| 108 | } |
| 109 | |
| 110 | Json applyAddOperation(Json const& base, Json const& op) { |
| 111 | String path = op.getString("path"); |
| 112 | auto value = op.get("value"); |
| 113 | auto pointer = JsonPath::Pointer(path); |
| 114 | |
| 115 | if (op.contains("search")) { |
| 116 | auto searchable = pointer.get(base); |
| 117 | auto searchValue = op.get("search"); |
| 118 | if (size_t index = findJsonMatch(searchable, searchValue, pointer)) |
| 119 | return pointer.add(pointer.remove(base), searchable.insert(index - 1, value)); |
| 120 | else |
| 121 | return base; |
| 122 | } else { |
| 123 | return pointer.add(base, value); |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | Json applyReplaceOperation(Json const& base, Json const& op) { |
| 128 | String path = op.getString("path"); |