Skip to content

A serialization/deserialization library for Simplified JSON, the Bitsquid/Stingray flavor of JSON.

License

Notifications You must be signed in to change notification settings

sclu1034/serde_sjson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serde_sjson

A serialization/deserialization library for Simplified JSON, the Bitsquid/Stingray flavor of JSON.

Usage

Serializing

use serde::Serialize;
use serde_sjson::Result;

#[derive(Serialize)]
struct Person {
    name: String,
    age: u8,
    friends: Vec<String>,
}

fn main() -> Result<()> {
    let data = Person {
        name: String::from("Marc"),
        age: 21,
        friends: vec![String::from("Jessica"), String::from("Paul")],
    };

    let s = serde_sjson::to_string(&data)?;

    println!("{}", s);

    Ok(())
}

Deserializing

use serde::Deserialize;
use serde_sjson::Result;

#[derive(Deserialize)]
struct Person {
    name: String,
    age: u8,
    friends: Vec<String>,
}

fn main() -> Result<()> {
    let sjson = r#"
    name = Marc
    age = 21
    friends = [
        Jessica
        Paul
    ]"#;

    let data: Person = serde_sjson::from_str(sjson)?;

    println!(
        "{} is {} years old and has {} friends.",
        data.name,
        data.age,
        data.friends.len()
    );

    Ok(())
}

About

A serialization/deserialization library for Simplified JSON, the Bitsquid/Stingray flavor of JSON.

Resources

License

Stars

Watchers

Forks

Packages

No packages published