Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/secomind/exjsonpath
JSONPath library for Elixir
https://github.com/secomind/exjsonpath
elixir elixir-library json jsonpath
Last synced: 2 months ago
JSON representation
JSONPath library for Elixir
- Host: GitHub
- URL: https://github.com/secomind/exjsonpath
- Owner: secomind
- License: apache-2.0
- Created: 2019-06-24T16:15:27.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2022-02-17T16:48:59.000Z (almost 3 years ago)
- Last Synced: 2024-03-15T02:47:34.252Z (10 months ago)
- Topics: elixir, elixir-library, json, jsonpath
- Language: Elixir
- Size: 110 KB
- Stars: 23
- Watchers: 3
- Forks: 6
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ExJsonPath
ExJsonPath is an Elixir library which allows to query maps (JSON objects) and lists (JSON arrays),
using [JSONPath](https://goessner.net/articles/JsonPath/) expressions.ExJsonPath is not limited to JSON, but allows to query nearly any kind of map or list, with just
one main restriction: keys have to be strings.## Installation
- Add `ExJsonPath` dependency to your project's `mix.exs`:```elixir
def deps do
[
{:exjsonpath, "~> 0.1"}
]
end
```
- Run `mix deps.get`## Basic Usage
```elixir
iex(1)> ExJSONPath.eval([%{"v" => 1}, %{"v" => 2}, %{"v" => 3}], "$[?(@.v > 1)].v")
{:ok, [2, 3]}
``````elixir
iex(1)> {:ok, json} = File.read("store.json")
iex(2)> {:ok, store} = Jason.decode(json)
iex(3)> ExJSONPath.eval(store, "$.store.book[?(@.price > 20)].title")
{:ok, ["The Lord of the Rings"]}
```Full documentation can be found at [hexdocs.pm/exjsonpath](https://hexdocs.pm/exjsonpath).
## Notes
Expressions with no leading selector (`$` or `@`) default to current item, however they are a
common extension to JSONPath that should be avoided for compatibility reasons.## About This Project
This project has been created in order to provide support to JSONPath to [Astarte Flow](https://github.com/astarte-platform/astarte_flow).
We are open to any contribution and we encourage adoption of this library to anyone looking for a maps and lists query language.