Releases: jg-rp/python-jsonpath
Releases · jg-rp/python-jsonpath
Version 1.0.0
RFC 9535 (JSONPath: Query Expressions for JSON) is now out, replacing the draft IETF JSONPath base.
Breaking Changes
- The undocumented
keysfunction extension is no longer enabled by default. A new, well-typedkeysfunction is planned for the future.
Fixes
- The lexer now sorts environment-controlled tokens by their length in descending order. This allows one custom token to be a prefix of another.
Features
- Added the non-standard "fake root" identifier, which defaults to
^and can be customized with thefake_root_tokenattribute on aJSONPathEnvironmentsubclass. Using the fake root identifier is equivalent to the standard root identifier ($), but wraps the target JSON value in an array, so the root value can be conditionally selected using a filter. - Non-standard environment-controlled tokens can now be disabled by setting them to the empty string.
Version 0.10.3
Breaking Changes
- Changed the exception raised when attempting to compare a non-singular filter query from
JSONPathSyntaxErrortoJSONPathTypeError.
Fixes
- Fixed handling of relative and root queries when used as arguments to filter functions. Previously, when those queries resulted in an empty node list, we were converting them to an empty regular list before passing it to functions that accept ValueType arguments. Now, in such cases, we convert empty node lists to the special result Nothing, which is required by the spec.
- Fixed well-typedness checks on JSONPath logical expressions (those that involve
&&or||) and non-singular filter queries. Previously we were erroneously applying the checks for comparison expressions to logical expressions too. Now non-singular queries in logical expressions act as an existence test. See #45.
Version 0.10.2
Fixes
- Fixed precedence of the logical not operator in JSONPath filter expressions. Previously, logical or and logical and had priority over not. See #41.
Version 0.10.1
Hot fix
- Fixed priority of JSONPath lexer rules. Previously, standard short tokens (like
*and?) had a higher priority than environment controlled tokens (likeJSONPathEnvironment.keys_selector_token), making it impossible to incorporate short token characters into longer environment-controlled tokens.
Version 0.10.0
Breaking Changes
- We now enforce JSONPath filter expression "well-typedness" by default. That is, filter expressions are checked at compile time according to the IETF JSONPath Draft function extension type system and rules regarding non-singular query usage. If an expression is deemed to not be well-typed, a
JSONPathTypeErroris raised. This can be disabled in Python JSONPath by setting thewell_typedargument toJSONPathEnvironmenttoFalse, or using--no-type-checkson the command line. See #33. - The JSONPath lexer and parser have been refactored to accommodate #30. As a result, the tokens generated by the lexer and the ATS built by the parser have changed significantly. In the unlikely event that anyone is customizing the lexer or parser through subclassing, please open an issue and I'll provide more details.
- Changed the normalized representation of JSONPath string literals to use double quotes instead of single quotes.
- Changed the normalized representation of JSONPath filter expressions to not include parentheses unless the expression includes one or more logical operators.
- The built-in implementation of the standard
length()filter function is now a class and is renamed tojsonpath.function_extensions.Length. - The built-in implementation of the standard
value()filter function is now a class and is renamed tojsonpath.function_extensions.Value.
Fixes
- We no longer silently ignore invalid escape sequences in JSONPath string literals. For example,
$['\"']used to be OK, it now raises aJSONPathSyntaxError. See #31. - Fixed parsing of JSONPath integer literals that use scientific notation. Previously we raised a
JSONPathSyntaxErrorfor literals such as1e2. - Fixed parsing of JSONPath comparison and logical expressions as filter function arguments. Previously we raised a
JSONPathSyntaxErrorif a comparison or logical expression appeared as a filter function argument. Note that none of the built-in, standard filter functions accept arguments ofLogicalType. - Fixed parsing of nested JSONPath filter functions, where a function is used as an argument to another.
- Fixed JSONPath bracketed segments. We now handle an arbitrary number of filter selectors alongside name, index, slice and wildcard selectors, separated by commas. See #30.
Version 0.9.0
Breaking Changes
CompoundJSONPathinstances are no longer updated in-place when using.union()and.intersection(). Instead, a newCompoundJSONPathis returned.CompoundJSONPath.pathsis now a tuple instead of a list.
Fixes
- Fixed a bug with the parsing of JSON Pointers. When given an arbitrary string without slashes,
JSONPointerwould resolve to the document root. The empty string is the only valid pointer that should resolve to the document root. We now raise aJSONPointerErrorin such cases. See #27. - Fixed handling of JSON documents containing only a top-level string.
Features
- Added a command line interface, exposing JSONPath, JSON Pointer and JSON Patch features (docs, source).
- Added
JSONPointer.parent(), a method that returns the parent of the pointer, as a newJSONPointer(docs). - Implemented
JSONPointer.__truediv__()to allow creation of child pointers from an existing pointer using the slash (/) operator (docs). - Added
JSONPointer.join(), a method for creating child pointers. This is equivalent to using the slash (/) operator for each argument given tojoin()(docs). - Added
JSONPointer.exists(), a method that returnsTrueif a the pointer can be resolved against some data, orFalseotherwise (docs). - Added the
RelativeJSONPointerclass for building newJSONPointerinstances from Relative JSON Pointer syntax (docs, API). - Added support for a non-standard index/property pointer using
#<property or index>. This is to support Relative JSON Pointer's use of hash (#) when buildingJSONPointerinstances from relative JSON Pointers. - Added the
unicode_escapeargument toJSONPathEnvironment. WhenTrue(the default), UTF-16 escaped sequences found in JSONPath string literals will be decoded.
Version 0.8.1
Fixes
- Fixed the string representation of a
JSONPointerwhen built usingJSONPointer.from_parts()and pointing to the document root. See #21.
Version 0.8.0
Breaking changes
- Changed the
JSONPathMatch.partsrepresentation of the non-standard keys selector (default~) to be~followed by the key name. It used to be two "parts",~and key index. - All
FilterExpressionsubclasses must now implementchildren()andset_children(). These methods facilitate filter expression inspection and caching.
Fixes
- Changed
findall()andfinditer()to acceptdataarguments of anyio.IOBasesubclass, not justTextIO.
Features
- Added the
JSONPointerclass and methods for converting aJSONPathMatchto aJSONPointer.JSONPointeris compliant with RFC 6901 (docs). - Added the
JSONPatchclass.JSONPatchimplements RFC 6902 (docs). - Added
jsonpath.pointer.resolve(), a convenience function for resolving a JSON Pointer (docs). - Added
jsonpath.patch.apply(), a convenience function for applying a JSON Patch (docs). - Added
jsonpath.match(), a convenience function returning aJSONPathMatchinstance for the first match of a path, orNoneif there were no matches (docs). - Added filter expression caching. Controlled with the
filter_cachingargument toJSONPathEnvironment, filter expression caching is enabled by default. See [#14] - All selectors now use
env.match_classto instantiate newJSONPathMatchobjects. This allows for subclassing ofJSONPathMatch. - Added
jsonpath.filter.walk()for the benefit of filter expression static analysis.
Version 0.7.1
Fixes
- Fixed a bug with the filter context selector (default
_) when it's used as a filter function argument.
Version 0.7.0
Breaking changes
JSONPathIndexErrornow requires atokenparameter. It used to be optional.- Filter expressions that resolve JSON paths (like
SelfPathandRootPath) now return aNodeList. The node list must then be explicitly unpacked byJSONPathEnvironment.compare()and any filter function that has awith_node_listsattribute set toTrue. This is done for the benefit of thecount()filter function and standards compliance.
Features
missingis now an allowed alias ofundefinedwhen using theisinstance()filter function.
IETF JSONPath Draft compliance
- The built-in
count()filter function is now compliant with the standard, operating on a "nodelist" instead of node values.