Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
@davesnx/query-json
Advanced tools
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:
It was created with 2 reasons in mind, learn and fun:
menhir
and sedlex
while trying to create a compiler with great error messages and possibly recoverability (currently work in progress).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
}
]
$ 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...)filter(p)
as an alias for map(select(p))
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
npm install --global @davesnx/query-json
# or
yarn global add @davesnx/query-json
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"
.
q '.' pokemons.json
cat pokemons.json | q '.'
q --kind=inline '.' '{ "bulvasur": { "id": 1, "power": 20 } }'
q '.' pokemons.json --no-colors
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).
Badge | Meaning |
---|---|
✅ | Implemented |
⚠️ | Not implemented yet |
🔴 | Won't implement |
--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 ✅.
✅.foo
, .foo.bar
✅.foo?
✅.[<string>]
✅.[2]
✅|
✅.[10:15]
⚠️.[]
✅,
✅()
✅️+
✅-
✅*
, /
, 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)
⚠️@text
, @csv
, etc.. 🔴==
, !=
✅if-then-else
⚠️>
, >=
, <=
, <
✅and
, or
, not
⚠️break
🔴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@gmail.com).
I usually hang out at discord.gg/reasonml or reasonml.chat so feel free to ask anything there.
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
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.
FAQs
faster and simpler re-implementation of jq in Reason Native
We found that @davesnx/query-json demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.