1
2
3
4
5
6
7
8
9
10
11
use serde::{Deserialize, Serialize};

/// Normalizes the given value by deserializing it and serializing it back.
pub fn normalize_json<'de, S>(value: &'de str) -> anyhow::Result<String>
where
    S: Serialize + Deserialize<'de>,
{
    let deserialized: S = serde_json::from_str(value)?;
    let serialized = serde_json::to_value(&deserialized)?.to_string();
    Ok(serialized)
}