All Projects → davesnx → Query Json

davesnx / Query Json

Licence: bsd-3-clause
Faster and simpler implementation of jq in Reason Native

Programming Languages

ocaml
1615 projects
reason
219 projects

Projects that are alternatives of or similar to Query Json

Aws
A collection of bash shell scripts for automating various tasks with Amazon Web Services using the AWS CLI and jq.
Stars: ✭ 493 (-6.98%)
Mutual labels:  json
Coolie
Coolie(苦力) helps you to create models (& their constructors) from a JSON file.
Stars: ✭ 508 (-4.15%)
Mutual labels:  json
Brisk
✨Cross-platform set of tools for building native UIs with Reason/OCaml
Stars: ✭ 518 (-2.26%)
Mutual labels:  reasonml
Simd Json
Rust port of simdjson
Stars: ✭ 499 (-5.85%)
Mutual labels:  json
Acts as api
makes creating API responses in Rails easy and fun
Stars: ✭ 506 (-4.53%)
Mutual labels:  json
Aws Security Viz
Visualize your aws security groups.
Stars: ✭ 511 (-3.58%)
Mutual labels:  json
Element Api
Create a JSON API/Feed for your elements in Craft.
Stars: ✭ 493 (-6.98%)
Mutual labels:  json
Opa
An open source, general-purpose policy engine.
Stars: ✭ 5,939 (+1020.57%)
Mutual labels:  json
Sirdb
👨 a simple, git diffable JSON database on yer filesystem. By the power of NodeJS
Stars: ✭ 508 (-4.15%)
Mutual labels:  json
Simdjsonsharp
C# bindings for lemire/simdjson (and full C# port)
Stars: ✭ 506 (-4.53%)
Mutual labels:  json
Argonaut
Purely functional JSON parser and library in scala.
Stars: ✭ 501 (-5.47%)
Mutual labels:  json
Featureflags
🚩 Allows developers to configure feature flags, run multiple A/B tests or phase feature roll out using a JSON configuration file.
Stars: ✭ 506 (-4.53%)
Mutual labels:  json
Jsonnet
Jsonnet - The data templating language
Stars: ✭ 5,257 (+891.89%)
Mutual labels:  json
Networking
⚡️ Elegantly connect to a REST JSON Api. URLSession + Combine + Decodable + Generics = <3
Stars: ✭ 499 (-5.85%)
Mutual labels:  json
Reasonablytyped
💠 Converts Flow and TypeScript definitions to Reason interfaces
Stars: ✭ 525 (-0.94%)
Mutual labels:  reasonml
Strip Json Comments
Strip comments from JSON. Lets you use comments in your JSON files!
Stars: ✭ 492 (-7.17%)
Mutual labels:  json
Pmhttp
Swift/Obj-C HTTP framework with a focus on REST and JSON
Stars: ✭ 509 (-3.96%)
Mutual labels:  json
Lithium
Easy to use C++17 HTTP Server with no compromise on performances. https://matt-42.github.io/lithium
Stars: ✭ 523 (-1.32%)
Mutual labels:  json
Body Parser
Node.js body parsing middleware
Stars: ✭ 4,962 (+836.23%)
Mutual labels:  json
Ramda Cli
🐏 A CLI tool for processing data with functional pipelines
Stars: ✭ 515 (-2.83%)
Mutual labels:  json

query-json logo


Coverage Status Netlify Badge


query-json is a faster and simpler re-implementation of the jq language in Reason Native and distributed as a dependency-free binary thanks to the OCaml compiler. query-json, allows you to write small programs to operate on top of json files in a cute syntax:

Purpose

It was created with 2 reasons in mind, learn and fun:

  • Learn how to write a lexer/parser/compiler with the OCaml stack using menhir and sedlex while trying to create a compiler with great error messages and possibly recoverability (currently work in progress).
  • Create a CLI tool in Reason Native and being able to distribute it as a binary, enjoy it's performance and try further with cross-compilation.

Intro

query-json ".store.books | filter(.price > 10)" stores.json

This would access to "store" field inside the stores.json, access to "books" field, (since it's an array) it will run a filter on each item and if "price" field is bigger than 10 will keep that item on the list, and finally print the resultant list.

[
  {
    "title": "War and Peace",
    "author": "Leo Tolstoy",
    "price": 12.0
  },
  {
    "title": "Lolita",
    "author": "Vladimir Nabokov",
    "price": 13.0
  }
]

It brings

  • Great Performance: Fast, small footprint and minimum run-time. Check Performance section for a longer explanation.
  • Delightful errors:
    • Better errors when json types and operation don't match:
      $ query-json '.esy.release.wat' esy.json
      Error:  Trying to ".wat" on an object, that don't have the field "wat":
      { "bin": ... }
      
    • debug prints the tokens and the AST.
    • verbose flag, prints each operation in each state and it's intermediate states. (Work in progress...)
  • Improved API: made small adjustments to the buildin operations. Some examples are:
    • All methods are snake_case instead of alltoghetercase
    • Added filter(p) as an alias for map(select(p))
    • Supports comments in JSONs
  • Small: Lexer, Parser and Compiler are just 300 LOC and most of the commands that I use on my day to day are implemented in only 140 LOC.

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

    • --version
    • --kind. This is different than jq ✅
      • --kind=file and the 2nd argument can be a json file
      • --kind=inline and the 2nd argument can be a json as a string
    • --no-color. This disables colors ✅
    • ...rest ⚠️
  • Basic filters

    • Identity: .
    • Object Identifier-Index: .foo, .foo.bar
    • Optional Object Identifier-Index: .foo?
    • Generic Object Index: .[<string>]
    • Array Index: .[2]
    • Pipe: |
    • Array/String Slice: .[10:15] ⚠️
    • Array/Object Value Iterator: .[]
    • Comma: ,
    • Parenthesis: () ✅️
  • Types and Values ⚠️

  • Builtin operators and functions

    • Addition: +
    • Subtraction: -
    • Multiplication, division, modulo: *, /, and %
    • length
    • keys
    • map
    • select
    • has(key) ⚠️
    • in ⚠️
    • path(path_expression) ⚠️
    • to_entries, from_entries, with_entries ⚠️
    • any, any(condition), any(generator; condition) ⚠️
    • all, all(condition), all(generator; condition) ⚠️
    • flatten
    • range(upto), range(from;upto) range(from;upto;by) ⚠️
    • floor, sqrt ⚠️
    • tonumber, tostring ⚠️
    • type ⚠️
    • infinite, nan, isinfinite, isnan, isfinite, isnormal ⚠️
    • sort, sort_by(path_expression)
    • group_by(path_expression) ⚠️
    • min, max, min_by(path_exp), max_by(path_exp) ⚠️
    • unique, unique_by(path_exp) ⚠️
    • reverse ⚠️
    • contains(element) ⚠️
    • index(s), rindex(s) ⚠️
    • startswith(str), endswith(str) ⚠️
    • explode, implode ⚠️
    • split(str), join(str) ⚠️
    • while(cond; update), until(cond; next) ⚠️
    • recurse(f), recurse, recurse(f; condition), recurse_down ⚠️
    • walk(f) ⚠️
    • transpose(f) ⚠️
    • Format strings and escaping: @text, @csv, etc.. 🔴

Conditionals and Comparisons

  • ==, !=
  • if-then-else ⚠️
  • >, >=, <=, <
  • and, or, not ⚠️
  • break 🔴

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 ([email protected]).

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].