Releases: jg-rp/python-jsonpath
Release list
Versoin 2.2.1
Fixes
- JSONPath parser recursion limit failures now raise
JSONPathRecursionError, preserving the originalRecursionErroras the cause.JSONPathRecursionErrornow also subclassesRecursionError, allowing existing exceptRecursionErrorhandlers to continue working.
Version 2.2.0
Fixes
- Fixed lexing of quoted name selectors ending in an escaped backslash, like
$['a\\']['b']. The lexer's look-behind for the closing quote treated a quote following an escaped backslash (\\) as an escaped quote (\'), so these selectors failed to tokenize. This also broke the RFC 9535 normalized path round-trip: normalized paths produced for object keys containing backslashes could not be parsed back. See #132. - Fixed atomic JSONPatch application when a patch op replaces the document root.
Features
- Added
patch.patched(ops, data)andJSONPatch.patched(data).patched()is a non-mutating form of JSONPatch application. It always performs a deep copy ofdataand returns the patched copy. See #131.
Version 2.1.0
Added patch.atomic(patch, data) and JSONPatch.atomic(data). atomic() is similar to apply(), but preserves input data if a patch operation fails. See #129.
Version 2.0.2
Fixes
- Fixed parsing of non-standard JSONPath regular expression literals containing an escaped solidus (
/). This affected queries using the regex operator=~, like$.some[?(@.thing =~ /fo\/[a-z]/)], not standardmatchandsearchfunctions. See #124.
Version 2.0.1
Fixes
-
Fixed JSON pointers with negative indices.
Previously, negative indices were resolved against array-like values, but the JSON Pointer specification (RFC 6901) does not permit negative array indexes. We now raise a
JSONPointerIndexErrorwhen a JSON Pointer attempts to resolve an array element using a negative index.For users who require negative indices in JSON Pointers, you can set
JSONPointer.min_int_indexto a suitably negative integer, likeJSONPointer.min_int_index = -(2**53) + 1.See #116.
-
Fixed the JSON Patch
addoperation.Previously, a
JSONPatchErrorwas raised when pointing to an array index equal to the array's length. Now we append to arrays in such cases. See #117.
Version 2.0.0
JSONPath syntax changes
These breaking changes affect the default configuration of Python JSONPath. Version 2 also introduces a new strict mode, which enforces full compliance with RFC 9535. See optional dependencies and the syntax guide for details.
- Bracket notation - unquoted property names are no longer treated as quoted names.
- Before:
$[foo],$['foo'], and$["foo"]were equivalent. - Now:
$[foo]is a singular query selector. With an implicit root identifier,$.a[b]is equivalent to$.a[$.b]. See Singular query selector.
- Before:
- Filter expressions - float literals must follow the RFC.
.1is now invalid (use0.1)1.is now invalid (use1.0)
- Slice selectors - indexes and steps must follow the RFC.
- Leading zeros and negative zero are no longer valid and raise
JSONPathSyntaxError.
- Leading zeros and negative zero are no longer valid and raise
- Dot notation - no whitespace is allowed between
.or..and the following name. Whitespace before the dot is still permitted.
JSONPath function extension changes
- Added the
startswith(value, prefix)function extension. ReturnsTrueif both arguments are strings andprefixis a prefix ofvalue. See the filter functions documentation. - Reimplemented the non-standard
keys()function extension. It used to be a simple Python function,jsonpath.function_extensions.keys. Now it is a "well-typed" class,jsonpath.function_extensions.Keys. See the filter functions documentation. - Added
cache_capacity,debugandthread_safearguments tojsonpath.function_extensions.Matchandjsonpath.function_extensions.Searchconstructors.
JSONPath features
- Added the Keys filter selector.
- Added the Singular query selector.
- Match and search function extensions now use the
regexpackage (if installed) instead ofre. See optional dependencies. - Added the
strictargument to all convenience functions, the CLI and theJSONPathEnvironmentconstructor. Whenstrict=True, all non-standard extensions and relaxed parsing rules are disabled. - Added class variable
JSONPathEnvironment.max_recursion_depthto control the maximum recursion depth of descendant segments. - Improved exception messages (prettier, more informative).
Python API changes
- Renamed class variable
JSONPathEnvironment.fake_root_tokentoJSONPathEnvironment.pseudo_root_token.
Low level API changes
These only affect projects customizing the JSONPath lexer or parser.
- The tokens produced by the JSONPath lexer have changed. Previously we broadly skipped some punctuation and whitespace. Now the parser can make better choices about when to accept whitespace and do a better job of enforcing dots.
- We've change the internal representation of compiled JSONPath queries. We now model segments and selectors explicitly and use terminology that matches RFC 9535.
Version 1.3.2
Fixes
- Fixed JSONPath filter context data in embedded JSONPath queries. We were failing to pass on said context data when resolving embedded queries. See #103.
Version 1.3.1
Version 1.3.0
Fixes
- Fixed
jsonpath.JSONPathMatch.path. It is now a "normalized path" following section 2.7 of RFC 9535. - Fixed normalized slice indexes. We were failing to normalize some indexes given a negative step.
Other changes
jsonpath.match.NodeListis now re-exported asjsonpath.NodeList.- Added
jsonpath.NodeList.paths(), which returns a list of normalized paths, one for each node in the list. - Serialization of compiled JSONPath queries (instances of
jsonpath.JSONPath) has changed. String literals inside filter selectors are now serialized using the canonical format, as described in section 2.7 of RFC 9535, and parentheses in filter selectors are kept to a minimum.
Version 1.2.2
Fixes
- Fixed parsing of bare name selectors that start with a reserved word. See issue #72.
Changes
- We've dropped support for Python 3.7, which was end of life in June 2023.