greple -Mjq - greple module to search JSON data with jq
greple -Mjq --glob JSON-DATA --IN label pattern
Version 0.06
This is an experimental module for App::Greple to search JSON formatted text using jq(1) as a backend.
Search top level json object which includes both Marvin and Zaphod somewhere in its text representation.
Marvin
Zaphod
greple -Mjq 'Marvin Zaphod'
You can search object .commit.author.name includes Marvin like this:
.commit.author.name
greple -Mjq --IN .commit.author.name Marvin
Search first name field including Marvin under .commit:
name
.commit
greple -Mjq --IN .commit..name Marvin
Search any author.name field including Marvin:
author.name
greple -Mjq --IN author.name Marvin
Search name is Marvin and type is Robot or Android:
type
Robot
Android
greple -Mjq --IN name Marvin --IN type 'Robot|Android'
Please be aware that this is just a text matching tool for indented result of jq(1) command. So, for example, .commit.author includes everything under it and it matches committer field name. Use jq(1) filter for more complex and precise operation.
.commit.author
committer
greple(1) commands read entire input before processing. So it should not be used for gigantic data or infinite stream.
$ cpanm App::Greple::jq
Search pattern included in label field.
Character % can be used as a wildcard in label string. So %name matches labels end with name, and name% matches labels start with name.
%
%name
name%
If the label is simple string like name, it matches any level of JSON data.
If the label string contains period (.), it is considered as a nested labels. Name .name matches only name label at the top level. Name process.name matches only name entry of some process hash.
.
.name
process.name
process
If labels are separated by two or more dots (..), they don't have to have direct relationship.
..
Specify negative condition.
Specify required condition. If there is one or more required condition, all other positive rules move to optional. They are not required but highlighted if exist.
file at the top level.
file
path under .file.
path
.file
path in descendants of .file.
path at any level.
file.path at any level.
file.path
Some path in descendants of some file.
Any labels end with path.
Any labels start with path.
Any labels include path.
Search from any name labels.
greple -Mjq --IN name _mina
Search from .process.name label.
.process.name
greple -Mjq --IN .process.name _mina
Object .process.name contains _mina and .event contains EXEC.
_mina
.event
EXEC
greple -Mjq --IN .process.name _mina --IN .event EXEC
Object ppid is 803 and .event contains FORK or EXEC.
ppid
FORK
greple -Mjq --IN ppid 803 --IN event 'FORK|EXEC'
Object name is _mina and .event contains CREATE.
CREATE
greple -Mjq --IN name _mina --IN event 'CREATE'
Object ancestors contains 1132 and .event contains EXEC with arguments highlighted.
ancestors
1132
arguments
greple -Mjq --IN ancestors 1132 --IN event EXEC --IN arguments .
Object *pid label contains 803.
*pid
greple -Mjq --IN %pid 803
Object any <path> contains _mina under .file and .event contains WRITE.
WRITE
greple -Mjq --IN .file..path _mina --IN .event WRITE
Use --all option to show entire data.
--all
Use --nocolor option or set NO_COLOR=1 to disable colored output.
--nocolor
NO_COLOR=1
Use -o option to show only matched part.
-o
Use --blockend= option to cancel showing block separator.
--blockend=
Since this module implements original search function, greple(1) -i does not take effect. Set modifier in regex like (?i)pattern if you want case-insensitive match.
(?i)pattern
Use -Mjq::set=debug to see actual regex.
-Mjq::set=debug
Use -Mjq::set=noif if you don't have to use jq as an input filter. Data have to be well-formatted in that case.
-Mjq::set=noif
Use --color=always and set LESSANSIENDCHARS=mK if you want to see the output using less(1). Put next line in your ~/.greplerc to enable colored output always.
--color=always
LESSANSIENDCHARS=mK
option default --color=always
App::Greple, https://github.com/kaz-utashiro/greple
https://stedolan.github.io/jq/
Kazumasa Utashiro
Copyright ©︎ 2022-2024 Kazumasa Utashiro
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install App::Greple::jq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::Greple::jq
CPAN shell
perl -MCPAN -e shell install App::Greple::jq
For more information on module installation, please visit the detailed CPAN module installation guide.