A JSON compatable configure file parser
It's mainly for read not write from a human editable configure file in JSON.
Most of the configure key accessing methods are immutable.
Besides standar JSON, following features are supported:
- Comments begin with '#' which can take a whole line or trailing part of a line
- Both single and double quotation marks strings are allowed
- For JSON Arry and Object, trailing comma is allowed
Examples
Parse from str
use value;
let s = r##"
## this is a json conf file
##
{
## comment line
"null_key": null,
"i64_key": 1,
"i64_sci_key": 123E+4,
"i64_0x_key": 0xAf,
"f64_key": 3.14,
"f64_sci_key": 3.14e-2,
"true_key": true,
"false_key": false, # comment in line
'single_quote_key': 'a single quote value',
"object_key": {
"inner_key1": "abc",
"inner_key2": 3.14E3,
},
"array_key": [1, "abc", ],
}
"##;
println!;
println!;
let v = s..unwrap;
// basic accessing
println!;
assert!;
assert!;
assert!;
assert!;
assert!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
println!;
// iter over JSON Array
println!;
v.iter_array.for_each;
// iter over JSON Object
println!;
v.iter_object.for_each;
Load from str
use conf_json;
let v: Value = "\"abc\"".as_bytes.into;
assert_eq!;
Load from file
use conf_json;
let v = load_from_file.unwrap;
assert!;
assert_eq!;
Load from any type T t that implements std::io::Read trait
use conf_json;
let t = b"123";
let v: Value = t.as_slice.into;
assert_eq!;