MCPcopy Index your code
hub / github.com/InfinitiBit/graphbit / python_dict_to_json

Function python_dict_to_json

python/src/tools/registry.rs:430–440  ·  view source on GitHub ↗

Helper function to convert Python dict to JSON

(dict: &Bound<'_, PyDict>)

Source from the content-addressed store, hash-verified

428
429/// Helper function to convert Python dict to JSON
430fn python_dict_to_json(dict: &Bound<'_, PyDict>) -> PyResult<serde_json::Value> {
431 let mut map = serde_json::Map::new();
432
433 for (key, value) in dict.iter() {
434 let key_str = key.to_string();
435 let json_value = python_any_to_json(&value)?;
436 map.insert(key_str, json_value);
437 }
438
439 Ok(serde_json::Value::Object(map))
440}
441
442/// Helper function to convert Python Any to JSON
443fn python_any_to_json(value: &Bound<'_, PyAny>) -> PyResult<serde_json::Value> {

Callers 2

register_toolMethod · 0.85
python_any_to_jsonFunction · 0.85

Calls 3

python_any_to_jsonFunction · 0.85
to_stringMethod · 0.80
insertMethod · 0.80

Tested by

no test coverage detected