bettio

bettio

ExJSONPath - an Elixir JSONPath library

I am pleased to announce an initial release ExJSONPath.

ExJsonPath is an Elixir library which allows to query maps (JSON objects) and lists (JSON arrays), using JSONPath expressions.

We decided to implement ExJSONPath while working on Astarte Flow, since we wanted to allow users to query arbitrary JSON objects from their pipelines code.

ExJsonPath allows to query deserialized JSON files [1] using expressions similar to the following:

ExJsonPath.eval(store, "$.store.book[?(@.price > 20)].title")
{:ok, ["The Lord of the Rings"]}

ExJsonPath is not tied to JSON at all, the same kind of JSONPath expression can be used on any Elixir map or list.
Right now, the only hard requirement is that keys must be strings.

Hope you’ll find this useful :slight_smile:
Let me know if you have any request/question/feedback.

[1]:

{ "store": {
    "book": [ 
      { "category": "reference",
        "author": "Nigel Rees",
        "title": "Sayings of the Century",
        "price": 8.95
      },
      { "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
    }
  }
}

Most Liked

LostKobrakai

LostKobrakai

Looks interesting. I took a quick look at the code and it seems you’re recursing the structure manually. I’m wondering if it would make sense to convert to an Access pattern instead, so it could be used with get_in, put_in, … all by implementing one transformation from the JSONPath format to a list of Access accessors.

bettio

bettio

I know there are several software around that use it (e.g. kubectl).
The syntax is quite well known and there are tutorials, several tools (that allows users to test their expressions) and libraries in several languages.
So it was my first choice since it doesn’t require people to learn a new syntax.
I think you should focus your library to a specific use-case, my use-case was to allow people to write JSON templates and pipelines for arbitrary JSON inputs. As a side effect several kind of maps and lists are now supported by my JSONPath library.
I think I will add support to protocols and funs so I can extend my library to use-cases outside JSON.

Last Post!

koolquark

koolquark

Hi,
Is there any support for regex matching in filter expressions ?

Where Next?

Popular in Announcing Top

KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36689 110
New
danschultzer
In short Plug n’ play OAuth 2.0 provider library. Just set up a resource owner schema with Ecto (your user schema), install the dependen...
New
treble37
Just looking for a little feedback on a tiny helper library I built - Sometimes I find the need to convert maps with atom keys to maps w...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New
Flo0807
Hello everyone! I am excited to share our heart project Backpex with you. After building several Phoenix applications, we realized that...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54092 488
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 44167 214
New
TunkShif
This post is an instruction guide to help you setup your Neovim for Elixir development from scratch. It includes general information on h...
274 42576 114
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New

We're in Beta

About us Mission Statement