Skip to main content

json_to_toml

Function json_to_toml 

Source
pub fn json_to_toml(json: &str) -> Result<String, Box<dyn Error>>
Expand description

Converts a JSON value to TOML.

JSON arrays at the root are wrapped in {item: [...]} because TOML requires a table at the document root. Null values are skipped, since TOML has no null type; JSON arrays containing null error out.

§Errors

Returns an error if the JSON is malformed or contains values TOML cannot represent (null inside arrays, integers outside i64 range).

§Examples

use sheeter_engine::json_to_toml;
let toml = json_to_toml(r#"{"a":1}"#).unwrap();
assert!(toml.contains("a = 1"));