decode

Function decode 

Source
pub fn decode(input: &str, options: &DecodeOptions) -> ToonResult<Value>
Expand description

Decode a TOON string to a JSON value with custom options.

ยงExamples

use serde_json::json;
use toon_format::{
    decode,
    DecodeOptions,
    Delimiter,
};

let input = "name: Alice\nage: 30";
let options = DecodeOptions::new().with_strict(false);
let result = decode(input, &options)?;
assert_eq!(result["name"], json!("Alice"));
Examples found in repository?
examples/parts/decode_strict.rs (line 11)
6pub fn decode_strict() {
7    // Malformed: header says 2 rows, but only 1 provided
8    let malformed = "items[2]{id,name}:\n  1,Ada";
9
10    let opts = DecodeOptions::new().with_strict(true);
11    match decode(malformed, &opts) {
12        Ok(val) => println!("Unexpectedly decoded: {val}"),
13        Err(err) => println!("Strict decode error: {err}"),
14    }
15}