Crate rsjson

source ·
Expand description

Json file parser library

§Installation

...
[dependencies]
rsjson = "0.3.6";

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
let json: Result<rsjson::Json, String> = rsjson::Json::fromString("{\"key\":\"value\"}");
  • in both previous cases, remeber to handle the eventual error (e.g. using match) or to call unwrap()

  • 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 label
json.editNode(
    "nodeLabel",
    "newNodeLabel"
);
  • edit a node’s content
json.editContent(
    "nodeLabel",
    rsjson::NodeContent::Bool(true)
);
  • remove a node
json.removeNode(
    "nodeLabel"
);

Structs§

Enums§