Encode a serde_json::Value as TOON or pretty-printed JSON.
(value: &Value, format: OutputFormat)
| 37 | |
| 38 | /// Encode a serde_json::Value as TOON or pretty-printed JSON. |
| 39 | pub fn format_structured(value: &Value, format: OutputFormat) -> Result<String> { |
| 40 | match format { |
| 41 | OutputFormat::Json => Ok(serde_json::to_string_pretty(value)?), |
| 42 | OutputFormat::Toon => { |
| 43 | let options = toon_format::EncodeOptions::default(); |
| 44 | Ok(toon_format::encode(value, &options)?) |
| 45 | } |
| 46 | OutputFormat::Text => Ok(serde_json::to_string_pretty(value)?), |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | #[cfg(test)] |
| 51 | mod tests { |
no outgoing calls