Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/vrcca/json_path_access

Converts JSONPath selectors into Access selectors
https://github.com/vrcca/json_path_access

elixir-lang hacktoberfest json-path

Last synced: about 2 months ago
JSON representation

Converts JSONPath selectors into Access selectors

Awesome Lists containing this project

README

        

# JsonPathAccess

This library converts JSONPath expressions into Access list. This is really useful when you want to use it with `get_in/2`, `drop_in/2`, etc.

## Example

Assuming we have this JSON:
```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": 19.95
}
}
}

```

You could access some fields using JSONPath selectors:

```elixir
json_path = JsonPathAccess.to_access("$.store.bicycle.price")
get_in(json, json_path)

json_path = JsonPathAccess.to_access("$.store.book[1]['category']")
get_in(json, json_path)
```

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `json_path_access` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:json_path_access, "~> 0.1.0"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at .

## TODO

This library attempts to implement this version of the spec: https://www.ietf.org/archive/id/draft-ietf-jsonpath-base-05.html

- [x] Root Selector
- [x] Dot Selector
- [x] Dot Wildcard Selector
- [x] Index Selector
- [x] Index Wildcard Selector
- [x] Array Slice Selector
- Note: Currently there is no support for negative steps.
- [ ] Filter Selector
- [ ] Descendant Selector
- [ ] List Selector