JQLite - The query language for JSON
from jay0072007@programming.dev to programming@programming.dev on 11 May 06:15
https://programming.dev/post/30128028

Created a simple query language for JSON data.

Features:

Here’s an example to get the list of adult friends:

$.friends[?(@.age >= 18)]

Runs in browsers, and Node.js

Documentation site: jqlite.vercel.app

GitHub: github.com/Jay-Karia/jqlite

NPM Package: www.npmjs.com/package/jqlite-ts

⭐ Leaving a star on GitHub is much appreciated!

#programming

threaded - newest

Thorry84@feddit.nl on 11 May 08:12 next collapse

You might want to look into using some form of parameterized queries.

jay0072007@programming.dev on 11 May 09:05 collapse

Thanks for your suggestion! It’s definitely something I’ll look into.

SchwertImStein@lemmy.dbzer0.com on 11 May 08:22 next collapse

github.com/bazaarvoice/jolt

jay0072007@programming.dev on 11 May 09:39 collapse

That’s a great project! JQLite is mainly focused on query-style approach. Also it’s a hobby project for learning parsers and stuff.

Azzu@lemm.ee on 11 May 09:01 next collapse

jqlang.org

I’ve been using that for all my JSON extraction and processing needs. Let me automate a bunch of my builds for JS stuff for FoundryVTT gitlab.com/foundry-azzurite/pings/-/…/build.sh

jay0072007@programming.dev on 11 May 09:43 collapse

Thanks for sharing the project! JQLite is aimed to run in browsers and node, but will definitely take inspiration from “jq”.

Azzu@lemm.ee on 11 May 09:48 collapse

I just kinda wonder why when you’re in a browser or node, you wouldn’t just do

const json = {...};
json.friends.filter(f => f.age >= 18);

why learn another language when you already literally got the language to process JavaScript Object Notation right there.

jay0072007@programming.dev on 11 May 10:30 collapse

100% agreed. It’s just a learning/hobby project, to know more about parsers, and how languages work. Some of the features like Wildcard, Multiple key selection/omission comes handy, and might add more features like that.

Azzu@lemm.ee on 11 May 11:37 collapse

Totally fair. Sounds fun :)

_Vi@programming.dev on 11 May 12:58 next collapse

At first I thought that it is like SQLite, but for JSON, not just “JQ-lite”.


Speaking of JSON and queries, it is worth to mention DuckDB’s JSON features. This allows you to use actual SQL to query JSON.

Here is example of a DuckDB analogue of $.orders[?(@.status.#equals(‘delivered’))][*].items from JQLite documentation:

duckdb -c "from (from demo.json select unnest(orders)->>'status' as status, cast(unnest(orders)->'items' as json[]) as items) select unnest(items) as delivered_items where status='delivered'"

┌─────────────────────────────────────────────────┐
│                 delivered_items                 │
│                      json                       │
├─────────────────────────────────────────────────┤
│ {"productId":"p1","quantity":1,"price":1299.99} │
│ {"productId":"p2","quantity":2,"price":1599.99} │
└─────────────────────────────────────────────────┘
jay0072007@programming.dev on 12 May 03:47 collapse

That’s actually great to query JSON with SQL! But as you can see the example from DuckDB is quite complex and unreadable as well.

And I have made this project for learning purpose and to challenge myself.

However, Thanks for sharing the project.

footfaults@lemmygrad.ml on 12 May 02:26 next collapse

But what about all those hours I spent torturing myself learning jq’s filter syntax, and jmespath ?

jay0072007@programming.dev on 12 May 03:48 collapse

JQLite is not any replacement for existing tools, it’s just a learning/hobby project.

angelmountain@feddit.nl on 12 May 04:30 collapse

Which animal’s @$$ does this whip?