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 Responses

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.

Where Next?

Popular in Announcing Top

jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
ostinelli
Let’s write a database! Well not really, but I think it’s a little sad that there doesn’t seem to be a simple in-memory distributed KV da...
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 43622 214
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
blatyo
The best overview for how things are tied together is this presentation. Modules and functions are pretty well documented at this point, ...
New
Flo0807
Hello everyone! I am excited to share our heart project Backpex with you. After building several Phoenix applications, we realized that...
New
Jskalc
Hi! Today, after a couple weeks of development I’ve released v0.1 of LiveVue. It’s a seamless integration of Vue and Phoenix LiveView, i...
New
michalmuskala
Hello everybody. I have just released Jason - a new JSON library. You might be wondering, why do we need a new library? The primary foc...
New
pkrawat1
Hey guyz We at @aviabird are working on a payment library in elixir/phoenix. We are targeting March 2018 to add 56 Gateways to it. Have...
New

Other popular topics Top

malloryerik
Hi, this is for people who, like me, have had some friction using .html.heex templates in VSCode. The solution seems to be, in a hyphena...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
JeremM34
Hello, how can I check the Phoenix version ? Thanks !
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
Lily
In templates/appointment/index.html.eex: <%= for appointment <- @appointments do %> <tr> <td><%= appoi...
New
baxterw3b
Hi guys, i’m new in the Elixir world, and i have to say, that i love it! i’m having some problem to understand anonymous functions with ...
New
stefanluptak
Hello everybody, usually, I use a 29" ultra-wide monitor for VSCode which can easily accomodate explorer (files panel) + file with code ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
joaquinalcerro
Hi there, I am working with Ecto-Postgresql and I need to call all of the records from a specific table but the table has 40,000 records...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement