MCPcopy Create free account
hub / github.com/GraphLite-AI/GraphLite / from_json

Method from_json

graphlite/tests/testutils/cli_fixture.rs:163–190  ·  view source on GitHub ↗

Parse query result from JSON output

(json_str: &str)

Source from the content-addressed store, hash-verified

161impl CliQueryResult {
162 /// Parse query result from JSON output
163 fn from_json(json_str: &str) -> Result<Self, Box<dyn std::error::Error>> {
164 // Find where JSON starts (skip any log lines before it)
165 let json_start = json_str.find('{').ok_or("No JSON found in output")?;
166
167 let json_portion = &json_str[json_start..];
168 let parsed: JsonValue = serde_json::from_str(json_portion)?;
169
170 // Extract rows from JSON
171 let empty_vec = vec![];
172 let rows = parsed["rows"].as_array().unwrap_or(&empty_vec);
173
174 let converted_rows: Vec<Row> = rows
175 .iter()
176 .map(|row| {
177 let mut values = HashMap::new();
178 if let Some(obj) = row.as_object() {
179 for (key, val) in obj {
180 values.insert(key.clone(), json_value_to_storage_value(val));
181 }
182 }
183 Row { values }
184 })
185 .collect();
186
187 Ok(CliQueryResult {
188 rows: converted_rows,
189 })
190 }
191
192 /// Get the number of rows
193 pub fn len(&self) -> usize {

Callers

nothing calls this directly

Calls 5

as_arrayMethod · 0.80
cloneMethod · 0.80
iterMethod · 0.45
insertMethod · 0.45

Tested by

no test coverage detected