ic_query/subnet_catalog/json.rs
1//! Module: subnet_catalog::json
2//!
3//! Responsibility: decode, validate, and encode subnet catalog JSON payloads.
4//!
5//! Does not own: cache paths, catalog fetching, or human text rendering.
6//!
7//! Boundary: keeps wire/file JSON conversion centralized so callers work with
8//! validated domain structs.
9
10use super::{CatalogError, SubnetCatalog};
11
12/// Decodes and validates one subnet catalog JSON payload.
13pub fn parse_catalog_json(data: &str) -> Result<SubnetCatalog, CatalogError> {
14 let catalog = serde_json::from_str::<SubnetCatalog>(data)?;
15 catalog.validate()?;
16 Ok(catalog)
17}
18
19/// Renders one subnet catalog JSON payload with stable pretty formatting.
20pub fn catalog_to_pretty_json(catalog: &SubnetCatalog) -> Result<String, CatalogError> {
21 Ok(serde_json::to_string_pretty(catalog)?)
22}