ezjson

Crates.ioezjson
lib.rsezjson
version0.2.0
sourcesrc
created_at2023-09-16 12:59:53.354447
updated_at2023-09-16 18:33:35.413526
descriptionA Rust crate who allows you to use json files easily
homepagehttps://github.com/ItsMeViipeR/json
repositoryhttps://github.com/ItsMeViipeR/json
max_upload_size
id974337
size14,269
Nicolas AMATI (ItsMeViipeR)

documentation

https://docs.rs/ezjson

README

JSON

JSON is a json specialized tool to write json files in a more readable way.

Installation

To install json, you need to have cargo installed.

Then, you can install json with the following command:

cargo add json

Usage

To use json, you need to add the following line to your code:

use json::JsonEditor;

Then, you can create a json object with the following syntax:

let mut json = JsonEditor::open_from_file("json_file.json").expect("Failed to create from file.");

After it, you can edit the json object with the following syntax:

json.add_key("int", 1).expect("Failed to add key");
json.add_key("float", 1.0).expect("Failed to add key");
json.add_key("string", "Hello World!").expect("Failed to add key");
json.add_key("bool", true).expect("Failed to add key");

Finally, you can save the json object with the following syntax:

json.save_to_file("json_file.json").expect("Failed to save to file.");

You can also read the json object with the following syntax:

let mut json = JsonEditor::open_from_file("json_file.json").expect("Failed to create from file.");
let values = json.json_data.as_object().expect("Failed to get object");

The values will be a &Map<String, Value>.

But you can also get it as Vec with the following syntax:

json.json_data.as_vec().expect("Failed to get vec");

The value will be an Option<&Vec<Value>>.

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

json is licensed under the MIT license.

Commit count: 6

cargo fmt