Command-line JSON processor with Kotlin dsl.
568
Modern cross-platform JSON processor with readable Kotlin syntax.
cat ~/Desktop/bdb.ndjson | analyze '.filter{it.bool("muted")}.sortedBy{it.long("size")}.take(7)'
example.ndjson file:
java -jar analyze.jar example.ndjson 'where{long("size") > 10} max{long("size")} select{int("id")}'
# or
cat example.ndjson | java -jar analyze.jar 'where{long("size") > 10} max{long("size")} select{int("id")}'
analyze:
mv analyze.jar /usr/local/bin/analyze.jar
echo "java -jar /usr/local/bin/analyze.jar \$@" > /usr/local/bin/analyze
chmod a+x /usr/local/bin/analyze
analyze file.ndsjon 'max {long("size")} top 3 where {bool("active")}'
cat file.ndjson | analyze 'top 5 where{!bool("active")} min{int("some")}'
analyze file.ndsjon 'top 5 min{between(time("first"), time("last"))}'
cat file.ndjson | analyze 'where { obj("arr").int(0) > 5 }'
analyze file.ndsjon 'where{!bool("broken")} top 3 min{ obj(4).obj("nested").bool("flag") }'
Start the container in current directory, for example, with example.ndjson file:
docker run -v `pwd`:`pwd` -w `pwd` -it --rm demidko/analyze 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 | analyze 'where{bool("active")} top 10'
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 analyze-all.jar 'where{bool("active")} top 10'
Execute command
docker build . -t analyze
Now you can run container, for example:
docker run -v `pwd`:`pwd` -w `pwd` -it --rm analyze example.ndjson 'where{bool("active")} top 10'
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 | ./analyze-all 'where{bool("active")} top 10'
Content type
Image
Digest
Size
359.2 MB
Last updated
about 5 years ago
docker pull demidko/analyze