Load a JSON file, returning an empty object on missing/invalid. Use this for **read-only** paths (healthcheck, `has_tracedecay`, etc.). For install/edit paths, use [`load_json_file_strict`] instead.
(path: &Path)
| 443 | /// Use this for **read-only** paths (healthcheck, `has_tracedecay`, etc.). |
| 444 | /// For install/edit paths, use [`load_json_file_strict`] instead. |
| 445 | pub fn load_json_file(path: &Path) -> serde_json::Value { |
| 446 | if path.exists() { |
| 447 | let contents = std::fs::read_to_string(path).unwrap_or_default(); |
| 448 | serde_json::from_str(&contents).unwrap_or_else(|_| serde_json::json!({})) |
| 449 | } else { |
| 450 | serde_json::json!({}) |
| 451 | } |
| 452 | } |
| 453 | |
| 454 | /// Load a JSON file for **editing**. Unlike [`load_json_file`], this returns |
| 455 | /// an error if the file exists but cannot be parsed, preventing silent data |