implement POSIX regexp support Introduce a new operator `~` and new `/.../eis` regular expression syntax. This allows filtering by regular expression, e.g. jsonfilter -s '[ "foo", "bar", "baz" ]' -e '$[@ ~ /^b/]' ... would yield the values `bar` and `baz`. Possible regular expression modifiers are: - `e` ... enable extended POSIX regular expressions - `i` ... perform case insensitive matches - `s` ... let ranges and `.` match the newline character A regular expression literal may occur on the left or the right side of the `~` operator, but not on both. In case neither side of the `~` operator is a regular expression, the right side will be treated as regular expression pattern. Non-string values are converted to their string representation before performing matching. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
main: implement array mode Implement a new option "-a" which turns on array mode, meaning that the program will attempt to parse multiple consecutive JSON objects from the source data and merge them into a JSON array. This is mainly useful for operating on JSON log files with one object per line. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
parser: allow root path specifications All a patch specification to be just '@' or '$' - this is mainly useful when exporting the keys of the toplevel object to the shell. Example: $ echo '{ "abc": 1, "def": 2 }' | jsonpath -e 'keys=@' export keys='abc'\ 'def'; Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Improve error reporting Keep track of the exact location the error occured in and switch the internal error description from a dynamic string buffer to an integer which either holds negative values for lexer errors or positives values for grammer violations. In case of grammer violations the "error_code" member will hold a bitfield describing the expected tokens. Also rework the error messages emitted by the cli to be more precise. Examples: $ jsonfilter -s '{}' -e '@.foo bar' Syntax error: Expecting End of file In expression @.foo bar Near here ----------^ $ jsonfilter -s '{}' -e '@.foo\bar' Syntax error: Unexpected character In expression @.foo\bar Near here ---------^ $ jsonfilter -s '{}' -e '@.foo..bar' Syntax error: Expecting Label or '*' In expression @.foo..bar Near here ----------^ Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
Switch to sqlite3's lemon parser generator. This commit drops the flex + bison code in favor to a hand-written lexer and a new grammar file in lemon syntax. The change results in a much smaller binary and easier to maintain code. Code required to build and maintain the AST has been split off into the ast.c and ast.h files. Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>