# nu_plugin_json_path
This [nushell](https://github.com/nushell/nushell) plugin is an attempt to enable the use of `JSONPath`. You can read more about JSONPath in the specification [here](https://www.ietf.org/archive/id/draft-ietf-jsonpath-base-10.html).
## Example Input
This json file is taken from the JSONPath link above.
```json
{
"store": {
"book": [
{ "category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{ "category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
},
{ "category": "fiction",
"author": "Herman Melville",
"title": "Moby Dick",
"isbn": "0-553-21311-3",
"price": 8.99
},
{ "category": "fiction",
"author": "J. R. R. Tolkien",
"title": "The Lord of the Rings",
"isbn": "0-395-19395-8",
"price": 22.99
}
],
"bicycle": {
"color": "red",
"price": 399
}
}
}
```
## Syntax and Description
This table shows some example JSONPath syntax and the intended results for testing below.
|1|`$.store.book[*].author` |the authors of all books in the store|
|2|`$..author` |all authors|
|3|`$.store.*` |all things in store, which are some books and a red bicycle|
|4|`$.store..price` |the prices of everything in the store|
|5|`$..book[2]` |the third book|
|6|`$..book[-1]` |the last book in order|
|7|`$..book[0,1]`|the first two books|
|8|`$..book[:2]` |the first two books|
|9|`$..book[?(@.isbn)]` |all books with an ISBN number|
|10|`$..book[?(@.price<10)]` |all books cheaper than 10|
|11|`$..*` |all member values and array elements |contained in the input value
## Plugin Examples
I saved the above json in a file named test.json, which is also in the repository.
### Example 1
```sh
```sh
open test.json | json path '$.store..price'
```
```
╭───┬───────╮
│ 0 │ 399 │
│ 1 │ 8.95 │
│ 2 │ 12.99 │
│ 3 │ 8.99 │
│ 4 │ 22.99 │
╰───┴───────╯
```
### Example 5
```sh
```
╭───┬─────────────────┬──────────┬───────────────┬───────┬───────────╮
│ # │ author │ category │ isbn │ price │ title │
├───┼─────────────────┼──────────┼───────────────┼───────┼───────────┤
│ 0 │ Herman Melville │ fiction │ 0-553-21311-3 │ 8.99 │ Moby Dick │
╰───┴─────────────────┴──────────┴───────────────┴───────┴───────────╯
```
### Example 6
```sh
```
╭───┬──────────────────┬──────────┬───────────────┬───────┬───────────────────────╮
│ # │ author │ category │ isbn │ price │ title │
├───┼──────────────────┼──────────┼───────────────┼───────┼───────────────────────┤
│ 0 │ J. R. R. Tolkien │ fiction │ 0-395-19395-8 │ 22.99 │ The Lord of the Rings │
╰───┴──────────────────┴──────────┴───────────────┴───────┴───────────────────────╯
```
### Example 7
```sh
```
╭───┬──────────────┬───────────┬───────┬────────────────────────╮
│ # │ author │ category │ price │ title │
├───┼──────────────┼───────────┼───────┼────────────────────────┤
│ 0 │ Nigel Rees │ reference │ 8.95 │ Sayings of the Century │
│ 1 │ Evelyn Waugh │ fiction │ 12.99 │ Sword of Honour │
╰───┴──────────────┴───────────┴───────┴────────────────────────╯
```
### Example 8
```sh
```
╭───┬──────────────┬───────────┬───────┬────────────────────────╮
│ # │ author │ category │ price │ title │
├───┼──────────────┼───────────┼───────┼────────────────────────┤
│ 0 │ Nigel Rees │ reference │ 8.95 │ Sayings of the Century │
│ 1 │ Evelyn Waugh │ fiction │ 12.99 │ Sword of Honour │
╰───┴──────────────┴───────────┴───────┴────────────────────────╯
```
### Example 9
```sh
```
╭───┬──────────────────┬──────────┬───────────────┬───────┬───────────────────────╮
│ # │ author │ category │ isbn │ price │ title │
├───┼──────────────────┼──────────┼───────────────┼───────┼───────────────────────┤
│ 0 │ Herman Melville │ fiction │ 0-553-21311-3 │ 8.99 │ Moby Dick │
│ 1 │ J. R. R. Tolkien │ fiction │ 0-395-19395-8 │ 22.99 │ The Lord of the Rings │
╰───┴──────────────────┴──────────┴───────────────┴───────┴───────────────────────╯
```
### Example 10
```sh
```
╭───┬─────────────────┬───────────┬───────┬────────────────────────┬───────────────╮
│ # │ author │ category │ price │ title │ isbn │
├───┼─────────────────┼───────────┼───────┼────────────────────────┼───────────────┤
│ 0 │ Nigel Rees │ reference │ 8.95 │ Sayings of the Century │ ❎ │
│ 1 │ Herman Melville │ fiction │ 8.99 │ Moby Dick │ 0-553-21311-3 │
╰───┴─────────────────┴───────────┴───────┴────────────────────────┴───────────────╯
```
### Example 11
```sh
Good luck!