Modern cross-platform JSON processor with readable Kotlin syntax.
cat ~/Desktop/bdb.ndjson | kq '.filter{it.bool("muted")}.sortedBy{it.long("size")}.take(7)'
- You need jvm16 installed.
- Download release.
- Now you can run it, for example with
example.ndjson
file:java -jar kq.jar example.ndjson 'where{long("size") > 10} max{long("size")} select{int("id")}' # or cat example.ndjson | java -jar kq.jar 'where{long("size") > 10} max{long("size")} select{int("id")}'
- On Unix you can create command
kq
:mv kq.jar /usr/local/bin/kq.jar echo "java -jar /usr/local/bin/kq.jar \$@" > /usr/local/bin/kq chmod a+x /usr/local/bin/kq
kq file.ndsjon 'max {long("size")} top 3 where {bool("active")}'
cat file.ndjson | kq 'top 5 where{!bool("active")} min{int("some")}'
kq file.ndsjon 'top 5 min{between(time("first"), time("last"))}'
cat file.ndjson | kq 'where { obj("arr").int(0) > 5 }'
kq file.ndsjon 'where{!bool("broken")} top 3 min{ obj(4).obj("nested").bool("flag") }'
Usage with Docker
Start the container in current directory, for example, with example.ndjson
file:
docker run -v `pwd`:`pwd` -w `pwd` -it --rm demidko/kq example.ndjson 'where{bool("active")} max{long("size")} top 10'
Any request contains control constructs and inline expressions.
You can use any Kotlin sequence extension and following infix extensions in any order:
/* Sequence containing only elements matching the given predicate expression. */
where { /* expression */ }
/* Sequence sorted according to natural sort order of the value returned by specified selector expression. */
min { /* expression */ }
/* Sequence sorted descending according to natural sort order of the value returned by specified selector expression. */
max { /* expression */ }
/* Sequence containing first n elements. */
top(n)
/* Sequence containing the results of applying the given transform expression to each element in the original sequence */
select { /* expression */ }
You can use any Kotlin expression and following functions:
/* Subnode of current json node */
obj(name: String)
obj(idx: Int)
/* Logic value of current json node */
bool(name: String)
bool(idx: Int)
/* Integer number of current json node */
int(name: String)
int(idx: Int)
/* Double number of current json node */
double(name: String)
double(idx: Int)
/* Text value of current json node */
text(name: String)
text(idx: Int)
/* LocalDateTime value of current json node */
time(name: String)
time(idx: Int)
You need jvm16 installed.
Run ./install.sh
. Now you can run command, for example:
cat example.ndjson | kq 'where{bool("active")} top 10'
Build Java utility
Execute command:
./gradlew clean build
Your jar will be located at ./build/libs
with -all.jar
postfix. Now you can run jar, for
example:
cat example.ndjson | java -jar kq-all.jar 'where{bool("active")} top 10'
Build Docker image
Execute command
docker build . -t kq
Now you can run container, for example:
docker run -v `pwd`:`pwd` -w `pwd` -it --rm kq example.ndjson 'where{bool("active")} top 10'
Build cross-platform utility with GraalVM
Execute following commands:
./gradlew clean build
native-image --allow-incomplete-classpath -jar ./build/libs/*-all.jar
Your native utility without runtime dependencies will be located at current directory with -all
postfix. Now you can run utility, for example:
cat example.ndjson | ./kq-all 'where{bool("active")} top 10'