jgrep
Command line tool and API for parsing JSON documents based on logical expressions
- Provided by: jgrep (Version: 1.5.4-2)
- Report a bug
Command line tool and API for parsing JSON documents based on logical expressions
jgrep <expression> [options]
jgrep can be used for filtering the contents of a JSON (JavaScript Object Notation) file after having parsed it. The expressions can help testing for the presence or absence of certain elements in the file. They can also test the values of certain elements.
-s | --simple <FIELD...> Greps the JSON and only returns the value of the field(s) specified
-c | --compat Returns the JSON in its non-pretty flat form
-n | --stream Specify continuous input
-f | --flatten Flatten the results as much as possible
-i | --input <FILENAME> Target JSON file to use as input. If this option is not specified, jgrep will expect to find JSON content on the standard input.
-q | --quiet Quiet; don't write to stdout. Exit with zero status if match found.
-v | --verbose Verbose output that will list a document if it fails to parse
--start <FIELD> Starts the grep at a specific key in the document
--slice <RANGE> A range of the form 'n' or 'n..m', indicating which documents to extract from the final output
JGrep uses the following logical symbols to define expressions.
and [statement] and [statement] Evaluates to true if both statements are true
or [statement] and [statement] Evaluates true if either statement is true
not | ! ! [statement] not [statement] Inverts the value of statement
+ +[value] Returns true if value is present in the json document
- -[value] Returns true if value is not present in the json doument
( and ) (expression1) and expression2 Performs the operations inside the perentheses first.
A statement is defined as some value in a JSON document compared to another value.
Available comparison operators are =, <, >, <= and >=
Given the following JSON document:
the following are examples of valid expressions:
+foo returns true
-bar returns false
+foo and !(foo=2) returns true
!(foo>=2 and bar=null) or !(bar=null) returns true
Gabriel Filion