project/jsonpath.git
2 months agobuild: require CMake >= 3.10 due to dropped legacy support master
Hauke Mehrtens [Fri, 3 Oct 2025 17:32:44 +0000 (19:32 +0200)]
build: require CMake >= 3.10 due to dropped legacy support

CMake version 4.0 and later require minimum version of 3.5 or later.
Update to minimum version 3.10 which is the last not deprecated minimum
version.

CMake 3.10 was released in November 2017 and is included in Ubuntu 18.04.

Suggested-by: Hannu Nyman <[email protected]>
Signed-off-by: Hauke Mehrtens <[email protected]>
7 months agobuild: set GNU17 for lemon compilation
Robert Marko [Fri, 18 Apr 2025 10:26:29 +0000 (12:26 +0200)]
build: set GNU17 for lemon compilation

GCC15 has changed the default from GNU17 (Since GCC8) to GNU23 and this is
breaking lemon compilation.

So, simply set -std=gnu17 for lemon.c so it compiles again.

Link: https://github.com/openwrt/jsonpath/pull/4
Signed-off-by: Robert Marko <[email protected]>
22 months agomain: fix spurious premature parse aborts in array mode
Jo-Philipp Wich [Tue, 23 Jan 2024 07:55:43 +0000 (08:55 +0100)]
main: fix spurious premature parse aborts in array mode

When reading newline separated JSON (array mode), continue parsing even
if the JSON tokener signals success, as another object might follow.

Fixes: FS#3683
Fixes: openwrt#8703
Fixes: openwrt#11649
Fixes: openwrt#12344
Fixes: 8614470 ("main: implement array mode")
Signed-off-by: Jo-Philipp Wich <[email protected]>
3 years agojsonfilter: drop legacy json-c support
Sergey Ponomarev [Tue, 19 Jan 2021 07:14:16 +0000 (09:14 +0200)]
jsonfilter: drop legacy json-c support

The cmake logic is wrong (E.G. PKG_CHECK_FOR_MODULES fails unless all
modules are found), and the legacy libjson.so name is also used by the
other libjson (for example [1]) which provides an incompatible API,
so just drop it.

Backported from libubox cbf80de7f4df61960f386cb01a899cf4228d38f3

[1] http://sourceforge.net/projects/libjson/

Signed-off-by: Sergey Ponomarev <[email protected]>
[ wrapped commit description to 75 char limit ]
Signed-off-by: Christian Marangi <[email protected]>
7 years agoimplement POSIX regexp support
Jo-Philipp Wich [Sun, 4 Feb 2018 17:36:07 +0000 (18:36 +0100)]
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 <[email protected]>
7 years agolexer: fix encoding 7 bit escape sequences
Jo-Philipp Wich [Sun, 4 Feb 2018 17:25:04 +0000 (18:25 +0100)]
lexer: fix encoding 7 bit escape sequences

A misplaced paren caused escape sequences in the ranges \x00..\x7f,
\u0000..\u007f and \0..\177 to get improperly encoded into the
string buffer.

Signed-off-by: Jo-Philipp Wich <[email protected]>
7 years agomain: implement array mode
Jo-Philipp Wich [Sun, 4 Feb 2018 14:37:15 +0000 (15:37 +0100)]
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 <[email protected]>
9 years agoremove obsolete /opt/local include/lib directories on mac os x
Felix Fietkau [Sat, 2 Jul 2016 08:16:53 +0000 (10:16 +0200)]
remove obsolete /opt/local include/lib directories on mac os x

Signed-off-by: Felix Fietkau <[email protected]>
9 years agoremove --gc-sections for mac os x builds
Felix Fietkau [Sat, 2 Jul 2016 08:16:34 +0000 (10:16 +0200)]
remove --gc-sections for mac os x builds

Signed-off-by: Felix Fietkau <[email protected]>
9 years agocmake: Find libubox/list.h header file
Florian Fainelli [Fri, 1 Jul 2016 23:06:16 +0000 (16:06 -0700)]
cmake: Find libubox/list.h header file

Add a CMake FIND_PATH and INCLUDE_DIRECTORIES searching for
libubox/list.h.  Some external toolchains which do not include standard
locations would fail to find the header otherwise.

Signed-off-by: Florian Fainelli <[email protected]>
9 years agotreewide: replace [email protected] with [email protected]
Jo-Philipp Wich [Tue, 7 Jun 2016 12:29:56 +0000 (14:29 +0200)]
treewide: replace [email protected] with [email protected]

Signed-off-by: Jo-Philipp Wich <[email protected]>
9 years agocli: properly format 64bit values
Jo-Philipp Wich [Wed, 1 Jun 2016 14:47:00 +0000 (16:47 +0200)]
cli: properly format 64bit values

Signed-off-by: Jo-Philipp Wich <[email protected]>
9 years agoparser: allow root path specifications
Jo-Philipp Wich [Tue, 24 May 2016 15:06:50 +0000 (17:06 +0200)]
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 <[email protected]>
9 years agomain: Add basic help output
Karl Palsson [Wed, 3 Feb 2016 17:11:57 +0000 (17:11 +0000)]
main: Add basic help output

Add basic usage text to the binary and print it when invoked with -h
or with no arguments at all.

Signed-off-by: Karl Palsson <[email protected]>
Signed-off-by: Jo-Philipp Wich <[email protected]>
9 years agomatcher: fix segfault with subscript on non-array element
Jo-Philipp Wich [Wed, 3 Feb 2016 17:32:55 +0000 (18:32 +0100)]
matcher: fix segfault with subscript on non-array element

Signed-off-by: Jo-Philipp Wich <[email protected]>
9 years agocontrib: add ParseTrace prototype to parser skeleton
Jo-Philipp Wich [Wed, 3 Feb 2016 16:09:51 +0000 (17:09 +0100)]
contrib: add ParseTrace prototype to parser skeleton

Signed-off-by: Jo-Philipp Wich <[email protected]>
10 years agocli: prevent segfault if input file failed to open
Jo-Philipp Wich [Tue, 27 Oct 2015 12:42:00 +0000 (13:42 +0100)]
cli: prevent segfault if input file failed to open

Signed-off-by: Jo-Philipp Wich <[email protected]>
11 years agocli: implement limit flag
Jo-Philipp Wich [Thu, 19 Jun 2014 11:51:28 +0000 (13:51 +0200)]
cli: implement limit flag

The new "-l" flag allows limiting the number of results getting printed.
This is useful for expressions which match many items when only the first
is desired.

Signed-off-by: Jo-Philipp Wich <[email protected]>
11 years agomatcher.c: properly handle negative array indizes
Jo-Philipp Wich [Thu, 19 Jun 2014 10:08:08 +0000 (12:08 +0200)]
matcher.c: properly handle negative array indizes

Signed-off-by: Jo-Philipp Wich <[email protected]>
11 years agocli: add a flag to specify arbritary field separators
Jo-Philipp Wich [Thu, 19 Jun 2014 09:21:41 +0000 (11:21 +0200)]
cli: add a flag to specify arbritary field separators

This is useful to join values with a specified char instead of the
default space.

Signed-off-by: Jo-Philipp Wich <[email protected]>
11 years agoImprove error reporting
Jo-Philipp Wich [Wed, 18 Jun 2014 15:59:51 +0000 (17:59 +0200)]
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 <[email protected]>
11 years agocli: minor whitespace fix
Jo-Philipp Wich [Wed, 18 Jun 2014 09:33:41 +0000 (11:33 +0200)]
cli: minor whitespace fix

Signed-off-by: Jo-Philipp Wich <[email protected]>
11 years agoSwitch to sqlite3's lemon parser generator.
Jo-Philipp Wich [Sun, 15 Jun 2014 14:31:14 +0000 (16:31 +0200)]
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 <[email protected]>
11 years agobuild: use -ffunction-sections and --gc-sections
Jo-Philipp Wich [Fri, 13 Jun 2014 13:26:37 +0000 (15:26 +0200)]
build: use -ffunction-sections and --gc-sections

Signed-off-by: Jo-Philipp Wich <[email protected]>
11 years agocli: supress printing "null" in non-export mode, output strings unescaped
Jo-Philipp Wich [Mon, 6 Jan 2014 11:55:44 +0000 (11:55 +0000)]
cli: supress printing "null" in non-export mode, output strings unescaped

11 years agoUpdate copyright
Jo-Philipp Wich [Thu, 2 Jan 2014 12:51:59 +0000 (12:51 +0000)]
Update copyright

11 years agoparser: fix error reporting
Jo-Philipp Wich [Wed, 1 Jan 2014 21:39:23 +0000 (21:39 +0000)]
parser: fix error reporting

11 years agolexer, parser, matcher: extend grammar to allow comma separated keys/indexes as more...
Jo-Philipp Wich [Wed, 1 Jan 2014 21:38:08 +0000 (21:38 +0000)]
lexer, parser, matcher: extend grammar to allow comma separated keys/indexes as more readable alternative to or expressions

11 years agocli: gather all found items through a callback function
Jo-Philipp Wich [Wed, 1 Jan 2014 15:44:00 +0000 (15:44 +0000)]
cli: gather all found items through a callback function

11 years agomatcher: add user callback and support implicit index/key compares
Jo-Philipp Wich [Wed, 1 Jan 2014 15:39:20 +0000 (15:39 +0000)]
matcher: add user callback and support implicit index/key compares

- introduced callback argument in jp_match() which is invoked for each found json item
- when chaining strings or numbers in or expressions, implicitely match them against the current key

11 years agolexer: accept single quoted string literals
Jo-Philipp Wich [Tue, 31 Dec 2013 00:07:06 +0000 (00:07 +0000)]
lexer: accept single quoted string literals

11 years agoparser: fix order of declarations
Jo-Philipp Wich [Sun, 29 Dec 2013 21:31:35 +0000 (21:31 +0000)]
parser: fix order of declarations

11 years agocli: implemnt -s flag to pass json source as string argument
Jo-Philipp Wich [Sun, 29 Dec 2013 21:19:11 +0000 (21:19 +0000)]
cli: implemnt -s flag to pass json source as string argument

11 years agocli: additional flags and cleanup
Jo-Philipp Wich [Sun, 29 Dec 2013 21:05:44 +0000 (21:05 +0000)]
cli: additional flags and cleanup

* add -q flag to suppress error messages
* add -t flag to test type of result
* clean up exit codes to indicate success;
- 0 if all -t and -e expression yielded a result
- 1 if at least one -t or -e expression didn't match
- 125 when failed to open input file
- 126 when failed to parse json input
- 127 when the farser fails due to oom

11 years agoparser: change exitcode in case of oom errors
Jo-Philipp Wich [Sun, 29 Dec 2013 21:03:51 +0000 (21:03 +0000)]
parser: change exitcode in case of oom errors

11 years agoAmend gitignore
Jo-Philipp Wich [Sun, 29 Dec 2013 18:07:40 +0000 (18:07 +0000)]
Amend gitignore

11 years agoAdd gitignore file
Jo-Philipp Wich [Sun, 29 Dec 2013 18:07:00 +0000 (18:07 +0000)]
Add gitignore file

11 years agoeliminate global variables and use a private parser/lexer state
Jo-Philipp Wich [Sun, 29 Dec 2013 18:03:10 +0000 (18:03 +0000)]
eliminate global variables and use a private parser/lexer state

11 years agocmake: let generated lexer.c, parser.c depend on their respective source files, clean...
Jo-Philipp Wich [Sun, 29 Dec 2013 18:02:04 +0000 (18:02 +0000)]
cmake: let generated lexer.c, parser.c depend on their respective source files, clean generated headers

11 years agoRemove generated files
Jo-Philipp Wich [Sat, 28 Dec 2013 21:26:59 +0000 (21:26 +0000)]
Remove generated files

11 years agoInitial commit
Jo-Philipp Wich [Sat, 28 Dec 2013 21:25:20 +0000 (21:25 +0000)]
Initial commit