Expand description
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");
Macros§
Structs§
- Json
- Node
- Node struct represents a pair of label (String) and content (rsjson::NodeContent) implements a getter for both label and content