json-commons-0.1.2 has been yanked.
json-commons
A set of JSON common tools in Rust
Usage
use JSON;
Parsing Features
Parsing features allows to read a JSON content but in case of failure a panic error occurs
Reading a JSON String
let content = "{\"car\": {\"model\": \"Gurgel Itaipu E400\", \"color\": \"red\"}}";
let json = jsonc.read_str;
Reading a JSON File
let path = "/user/docs/myfile.json";
let json = jsonc.read_str;
Dotted Paths Features
The following examples uses this json content
Path Exists
You can check if the path exists
let json = jsonc.read_str;
jsonc.path_exists; // The output is True
jsonc.path_exists; // The output is True
jsonc.path_exists; // The output is False
jsonc.path_exists; // The output is False
Get Path
You can get any path as an optional
let json = jsonc.read_str;
jsonc.get_path; // The output is Ok, containing a JsonValue
jsonc.get_path; // The output is Ok, containing a JsonValue
jsonc.get_path; // The output is None
jsonc.get_path; // The output is None
Attention: The dotted path does not work in lists
List Features
Consider the following content
Parse to Vec
You can parse a list to a vec
let json = jsonc.read_str;
let cars = jsonc.get_path.unwrap;
jsonc.parse_to_vec; // The output is a vec of JsonValue, with len 2