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

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
tmbb
PhoenixWS - Websockets over Phoenix Channels Source code on Github here: GitHub - tmbb/phoenix_ws: Websockets implemented over Phoenix Ch...
New
seancribbs
Today I released a new dialyzer Mix task as the dialyzex package! At the time we started writing this task, the existing dialyzer integra...
New
ityonemo
Currently just starting out on a new mini-project - getting zig NIFs to run in elixir. https://github.com/ityonemo/zigler The idea here...
New
dbern
I’m excited to announce that TaxJar has developed and open-sourced DateTimeParser. We developed it because we found a need to parse user ...
New
devonestes
Introducing assertions, the library that helps you write really great test assertions! GitHub: GitHub - devonestes/assertions: Helpful a...
New
maltoe
Hello! Came here to announce ChromicPDF, a pet project PDF generator I’ve been working on for the past few months. Why another PDF gener...
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
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
marcuslankenau
I feel kind of stuck with the absence of a proper xml library for Elixir. Currently I use SweetXML which was ok for me more or less to pa...
New

Other popular topics Top

electic
Hi, I am new to Elixir. I am trying to use the DateTime component to insert a date into MySQL however the there seems to be no way to fo...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
hariharasudhan94
lets say i have a sample like a = 20; b = 10; if (a > b) do {:ok, "a"} end if (a < b) do {:ok, b} end if (a == b) do {:ok, "equa...
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
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
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
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement