#### change name to AJSON, see [issue](https://github.com/importcjj/a-json/issues/2)
Inspiration comes from [gjson](https://github.com/tidwall/gjson) in golang
## Installation
Add it to your `Cargo.toml` file:
```
[dependencies]
ajson = "0.3"
```
## Todo
* Add documentation
* Follow api-guidelines
* Update benchmark
* Optimize
## A simple example
AJSON get json value with specified path, such as `project.name` or `project.version`. When the path matches, it returns immediately!
```rust
let data = r#"
{
"project": {
"name": "ajson",
"maintainer": "importcjj",
"version": 0.1,
"rusts": ["stable", "nightly"]
}
}
"#;
let name = ajson::get(data, "project.name").unwrap().unwrap();
println!("{}", name.as_str()); // ajson
```
## Path Syntax
JSON example
```json
{
"name": {"first": "Tom", "last": "Anderson"},
"age":37,
"children": ["Sara","Alex","Jack"],
"fav.movie": "Deer Hunter",
"friends": [
{"first": "Dale", "last": "Murphy", "age": 44, "nets": ["ig", "fb", "tw"]},
{"first": "Roger", "last": "Craig", "age": 68, "nets": ["fb", "tw"]},
{"first": "Jane", "last": "Murphy", "age": 47, "nets": ["ig", "tw"]}
]
}
```
#### basic
Below is a quick overview of the path syntax, for more complete information please check out GJSON Syntax.
A path is a series of keys separated by a dot. A key may contain special wildcard characters '*' and '?'. To access an array value use the index as the key. To get the number of elements in an array or to access a child path, use the '#' character. The dot and wildcard characters can be escaped with '\'.
```
name.last >> "Anderson"
age >> 37
children >> ["Sara","Alex","Jack"]
children.# >> 3
children.1 >> "Alex"
child*.2 >> "Jack"
c?ildren.0 >> "Sara"
fav\.movie >> "Deer Hunter"
friends.#.first >> ["Dale","Roger","Jane"]
friends.1.last >> "Craig"
```
#### Escape character
Special purpose characters, such as ., *, and ? can be escaped with \.
```
fav\.movie "Deer Hunter"
```
#### Arrays
The # character allows for digging into JSON Arrays.To get the length of an array you'll just use the # all by itself.
```
friends.# 3
friends.#.age [44,68,47]
```
#### queries
You can also query an array for the first match by using #(...), or find all matches with #(...)#. Queries support the ==, !=, <, <=, >, >= comparison operators and the simple pattern matching % (like) and !% (not like) operators.
```
friends.#(last=="Murphy").first >> "Dale"
friends.#(last=="Murphy")#.first >> ["Dale","Jane"]
friends.#(age>45)#.last >> ["Craig","Murphy"]
friends.#(first%"D*").last >> "Murphy"
friends.#(nets.#(=="fb"))#.first >> ["Dale","Roger"]
```
#### construct
Basically, you can use selectors to assemble whatever you want, and of course, the result is still a json ;)
```
{name.first,age,"murphys":friends.#(last="Murphy")#.first}
[name.first,age,children.0]
```
```rust
ajson::get(json, "name.[first,last]").unwrap().unwrap().to_vec();
ajson::get(json, "name.first").unwrap().unwrap();
ajson::get(json, "name.last").unwrap().unwrap();
```
## Value
Value types.
```rust
enum Value {
String(String),
Number(Number),
Object(String),
Array(String),
Boolean(bool),
Null,
}
```
Value has a number of methods that meet your different needs.
```rust
value.get(&str) -> Option