plasticine / exjsonpath

JSONPath library for Elixir

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ExJsonPath

ExJsonPath is an Elixir library which allows to query maps (JSON objects) and lists (JSON arrays), using 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:
def deps do
  [
    {:exjsonpath, "~> 0.1"}
  ]
end
  • Run mix deps.get

Basic Usage

iex(1)> ExJsonPath.eval([%{"v" => 1}, %{"v" => 2}, %{"v" => 3}], "$[?(@.v > 1)].v")
{:ok, [2, 3]}
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.

About This Project

This project has been created in order to provide support to JSONPath to 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.

About

JSONPath library for Elixir

License:Apache License 2.0


Languages

Language:Elixir 88.4%Language:Erlang 11.6%