Crates.io | rust_json |
lib.rs | rust_json |
version | 0.1.5 |
source | src |
created_at | 2022-09-18 05:57:15.479301 |
updated_at | 2022-09-22 03:52:56.025594 |
description | A simple JSON serializer and deserializer |
homepage | |
repository | https://github.com/Puellaquae/rust-json |
max_upload_size | |
id | 668497 |
size | 27,149 |
JSON serializer and deserializer written for learning rust.
use rust_json::json_parse;
fn example() {
let j = json_parse(r#"
{
"S": [
1,
2.3,
{
"4": {
"5": {
"6": [
null,
true,
false
]
}
}
}
]
}"#);
println!("{}", j["S"]);
}
use rust_json::json;
fn example() {
let j = json!(
{
"S": [
1.2,
"2.3",
{
"4": {
"5": {
"6": [
null,
true,
false
]
}
}
}
]
}
);
println!("{}", j["S"]);
}
use rust_json::js_object;
fn proc(n: i32) -> i32 {
n * n + n / 2
}
fn main() {
let a = true;
let n = 32;
let j = js_object!([
{
a // 属性的简洁表示 Property Shorthand
},
{
// 使用表达式作为值 Using expression
proc_n: if n % 2 == 0 { proc(n) + 1 } else { 0 },
[n * 12]: n * 12 // 属性名表达式 Computed Property Names
}
]);
println!("{}", j);
}
Impl the ToJson
and FromJson
to serialize and deserialize custom struct. Or you can use rust_json_derive to derive the traits.
use rust_json::json;
fn example() {
let j = json!({"a": 12});
println!("{:#}", j);
// {
// "a": 12
// }
println!("{:3}", j);
// {
// "a": 12
// }
}