DEV Community

Cover image for JQLite - The query language for JSON
Jay
Jay

Posted on

JQLite - The query language for JSON

Hey guys!

Created a simple query language for JSON in Typescript.

This is a learning/hobby project to know more about parser, and how languages work.

Features:

  • Basic query selection
  • Fallback Mechanism
  • Wildcard support
  • Array Slices
  • Multiple Key Selection
  • Key Omission
  • Single Key Omission
  • Functions
  • Comparison Operators
  • Conditions
  • Configurable

Here's a simple guide to get started:

import { config, data, query } from 'jqlite-ts';

// Load the data from a JSON file
data.load("./data.json");

// Override the default config
config.set({
  fallback: "No data found!"
});

// Run the query
query.run("$.friends[*].(name, age)", (result) => {
  console.log(result);
});
Enter fullscreen mode Exit fullscreen mode

Few examples:

  • Get the list of all products which has an average review more than 4
    $.products[?(@.reviews.#avg() > 4)]

  • Filter the products which has a price greater than 1500.
    $.products[?(@.price > 1500)]

  • Get the list of all delivered items
    $.orders[?(@.status.#equals('delivered'))][*].items


Documentation: https://jqlite.vercel.app/
GitHub: https://github.com/Jay-Karia/jqlite
NPM: https://www.npmjs.com/package/jqlite-ts


⭐ Leaving a star on GitHub is much appreciated!

Top comments (1)