davesnx / query-json

Faster, simpler and more portable implementation of `jq` in Reason
https://query-json.netlify.app
BSD 3-Clause "New" or "Revised" License
591 stars 6 forks source link
json menhir ocaml reason reason-native reasonml sedlex



query-json logo query-json logo

query-json is a faster, simpler and more portable implementation of the jq language in Reason distributed as a dependency-free binary thanks to the OCaml compiler, and distributed to the web with js_of_ocaml.

query-json allows you to write small programs to operate on top of json files with a concise syntax.

asciicast

Purpose

It was created with mostly two reasons, learning and having fun.

It brings

Installation

Using a bash script

Check the content of scripts/install.sh before running anything in your local. Friends don't let friends curl | bash.

curl -sfL https://raw.githubusercontent.com/davesnx/query-json/master/scripts/install.sh | bash

Using npm/yarn

npm install --global @davesnx/query-json
# or
yarn global add @davesnx/query-json

Download zip files from GitHub

Usage

I recommend to write the query in single-quotes inside the terminal, since writting JSON requires double-quotes for accessing properties.

NOTE: I have aliased query-json to be "q" for short, you can set it in your dotfiles. alias q="query-json".

query a json file

q '.' pokemons.json

query from stdin

cat pokemons.json | q '.'

query a json inlined

q --kind=inline '.' '{ "bulvasur": { "id": 1, "power": 20 } }'

query without colors

q '.' pokemons.json --no-colors

Performance

This report is not an exhaustive performance report of both tools, it's a overview for the percieved performance of the user. Here I don't profile each tool and try to see what are the bootlenecks, since I assume that both tools have the penalty of parsing a JSON file. Simply run a bash script and analyze the results.

Aside from that, query-json doesn't have feature parity with jq which is ok at this point, but jq contains a ton of functionality that query-json misses. Adding the missing operations on query-json won't affect the performance of it, that could not be true for features like "modules" or "tests", which they will not be implemented in query-json.

The report shows that query-json is between 2x and 5x faster than jq in all operations tested and same speed (~1.1x) with huge files (> 100M).

Currently supported feature set:

Badge Meaning
Implemented
⚠️ Not implemented yet
🔴 Won't implement
Based on jq 1.6

CLI: Invoking jq

Basic filters

Types and Values ⚠️

Builtin operators and functions

Conditionals and Comparisons

Regular expressions (PCRE) ⚠️

Advanced features ⚠️

Assignment ⚠️

Modules ⚠️

Contributing

Contributions are what make the open source community such an amazing place to be, learn, inspire, and create. Any contributions you make are greatly appreciated. If you have any questions just contact me @twitter or email dsnxmoreno at gmail dot com.

Support

I usually hang out at discord.gg/reasonml or reasonml.chat so feel free to ask anything there.

Setup

Requirements: esy

git clone https://github.com/davesnx/query-json
cd query-json
esy # installs
esy test # runs unit tests with [rely](https://reason-native.com/docs/rely), live under test/.
esy bin # Run binary

Acknowledgements

Thanks to @EduardoRFS. Thanks to all the authors of dependencies that this project relies on: menhir, sedlex, yojson. Thanks to the OCaml and Reason Native team.