json_extract-0.1.2 has been yanked.
json-extract-macro
Access nested JSON in 1 line of code
This macro reduces boilerplate when using serde_json::Value variants when trying to get into a nested property.
let designer: = json_extract!;
println!;
or
if let Object = json_file
Macro args
The macro accepts 3 arguments:
- A &str containg the path, separated by "."
- The serde_json::Value variable to read.
- The type of the property we want to get.
Types supported
json_serde::Value has the following variants:
- Array
- Bool
- Null
- Number
- Object
- String
The third parameter to pass in the macro is a Rust type, so, things we can pass if we want to get data from some variants:
Value variant | Rust types |
---|---|
Array | Vec<String>, Vec<bool>, Vec<f64>, Vec<Value> ... |
Bool | bool |
Number | u32, i32, i64, f32, usize ... |
Object | Value |
String | String |
Null | not supported |