23 unstable releases (5 breaking)
0.6.0 | Jan 28, 2025 |
---|---|
0.5.1 | Sep 28, 2024 |
0.5.0 | Jul 20, 2024 |
0.2.2 | Mar 25, 2024 |
#1289 in Parser implementations
118 downloads per month
Used in 3 crates
20KB
473 lines
rsjson
- Json file parser library
Installation
- add to your Cargo.toml:
...
[dependencies]
rsjson = "0.6.0"
- or run the following command in terminal:
cargo add rsjson
Importation
- include the following line into your code
use rsjson;
lib.rs
:
Json file parser library
Installation
...
[dependencies]
rsjson = "0.6.0";
or run
cargo add rsjson
Importation
use rsjson;
Code example
- read and parse a json file
let json: Result<rsjson::Json, String> = rsjson::Json::fromFile("/path/to/file.json");
- read and parse a json structure from a string
- the string can be both "normal" and raw
let json: Result<rsjson::Json, String> = rsjson::json!(
r#"{
"key" : "value",
"second_key" : ["one", "two"]
}"#
);
-
in both previous cases, remeber to handle the eventual error (e.g. using
match
) or to callunwrap()
-
create an empty json instance
let json = rsjson::Json::new();
- add a node
json.addNode(
rsjson::Node::new(
"nodeLabel",
rsjson::NodeContent::Int(32)
)
);
- edit a node's content
json.setContent(
"nodeLabel",
rsjson::NodeContent::Bool(true)
);
- remove a node
json.remove(
"nodeLabel"
);
- check the existance of a label
let exists: bool = json.has("nodeLabel");