22 releases (4 breaking)

0.5.1 Sep 28, 2024
0.5.0 Jul 20, 2024
0.4.3 Jul 13, 2024
0.2.2 Mar 25, 2024

#1399 in Parser implementations


Used in 2 crates

AGPL-3.0-or-later

20KB
471 lines

rsjson

  • Json file parser library

crates.io repository

docs.rs documentation


Installation

  • add to your Cargo.toml:
...
[dependencies]
rsjson = "0.5.1"
  • 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.5.1";

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 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"
);

No runtime deps