get value by path(key1 / key2)
| 123 | |
| 124 | // get value by path(key1 / key2) |
| 125 | static json json_get_nested_values(const std::vector<std::string> & paths, const json & js) { |
| 126 | json result = json::object(); |
| 127 | |
| 128 | for (const std::string & path : paths) { |
| 129 | json current = js; |
| 130 | const auto keys = string_split<std::string>(path, /*separator*/ '/'); |
| 131 | bool valid_path = true; |
| 132 | for (const std::string & k : keys) { |
| 133 | if (valid_path && current.is_object() && current.contains(k)) { |
| 134 | current = current[k]; |
| 135 | } else { |
| 136 | valid_path = false; |
| 137 | } |
| 138 | } |
| 139 | if (valid_path) { |
| 140 | result[path] = current; |
| 141 | } |
| 142 | } |
| 143 | return result; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * this handles 2 cases: |
no outgoing calls
no test coverage detected