ic_query/subnet_catalog/json.rs
1//! Module: subnet_catalog::json
2//!
3//! Responsibility: decode, structurally validate, and encode raw subnet catalog JSON payloads.
4//!
5//! Does not own: cache paths, catalog fetching, or human text rendering.
6//!
7//! Boundary: parsed values remain untrusted raw evidence; authority validation is separate.
8
9use super::{CatalogError, RawSubnetCatalog};
10
11/// Decode and structurally validate one untrusted raw subnet catalog JSON payload.
12pub fn parse_catalog_json(data: &str) -> Result<RawSubnetCatalog, CatalogError> {
13 let catalog = serde_json::from_str::<RawSubnetCatalog>(data)?;
14 catalog.validate()?;
15 Ok(catalog)
16}
17
18/// Renders one subnet catalog JSON payload with stable pretty formatting.
19pub fn catalog_to_pretty_json(catalog: &RawSubnetCatalog) -> Result<String, CatalogError> {
20 Ok(serde_json::to_string_pretty(catalog)?)
21}