MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / read_json_object

Function read_json_object

atomic-agent/src/hooks/manifest.rs:249–270  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

247}
248
249fn read_json_object(path: &Path) -> AgentResult<Map<String, Value>> {
250 if !path.exists() {
251 return Ok(Map::new());
252 }
253 let content = std::fs::read_to_string(path).map_err(|e| AgentError::ConfigError {
254 operation: "read".to_string(),
255 path: path.to_path_buf(),
256 reason: e.to_string(),
257 })?;
258 if content.trim().is_empty() {
259 return Ok(Map::new());
260 }
261 let value: Value = serde_json::from_str(&content).map_err(|e| AgentError::ConfigError {
262 operation: "parse".to_string(),
263 path: path.to_path_buf(),
264 reason: e.to_string(),
265 })?;
266 match value {
267 Value::Object(map) => Ok(map),
268 _ => Ok(Map::new()),
269 }
270}
271
272fn write_json_object(path: &Path, root: &Map<String, Value>) -> AgentResult<()> {
273 if let Some(parent) = path.parent() {

Callers 3

install_from_manifestFunction · 0.85
uninstall_from_manifestFunction · 0.85
uninstall_prefixedFunction · 0.85

Calls 2

existsMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected