MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / json_get_nested_values

Function json_get_nested_values

smallthinker/tools/server/utils.hpp:125–144  ·  view source on GitHub ↗

get value by path(key1 / key2)

Source from the content-addressed store, hash-verified

123
124// get value by path(key1 / key2)
125static 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:

Callers 1

to_json_non_oaicompatMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected