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

Download history 5/week @ 2024-10-22 1/week @ 2024-11-12 9/week @ 2024-11-19 1/week @ 2024-11-26 4/week @ 2024-12-03 65/week @ 2024-12-10 105/week @ 2025-01-28 13/week @ 2025-02-04

118 downloads per month
Used in 3 crates

AGPL-3.0-or-later

20KB
473 lines

rsjson

  • Json file parser library

crates.io repository

docs.rs documentation


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

No runtime deps