rust_json

Latest Version

JSON serializer and deserializer written for learning rust.

Feature

Parse json from string

```rust use rustjson::jsonparse;

fn example() { let j = json_parse(r#" { "S": [ 1, 2.3, { "4": { "5": { "6": [ null, true, false ] } } } ] }"#);

println!("{}", j["S"]);

} ```

Construct JsonElem with json literal

```rust use rust_json::json;

fn example() { let j = json!( { "S": [ 1.2, "2.3", { "4": { "5": { "6": [ null, true, false ] } } } ] } );

println!("{}", j["S"]);

} ```

Construct JsonElem with js object literal style

```rust use rustjson::jsobject;

fn proc(n: i32) -> i32 { n * n + n / 2 }

fn main() { let a = true; let n = 32; let j = jsobject!([ { a // 属性的简洁表示 Property Shorthand }, { // 使用表达式作为值 Using expression procn: if n % 2 == 0 { proc(n) + 1 } else { 0 }, [n * 12]: n * 12 // 属性名表达式 Computed Property Names } ]); println!("{}", j); } ```

ToJson and FromJson traits

Impl the ToJson and FromJson to serialize and deserialize custom struct. Or you can use rustjsonderive to derive the traits.