Skip to content

Releases: jg-rp/python-jsonpath

Versoin 2.2.1

Choose a tag to compare

@jg-rp jg-rp released this 07 Jul 09:57

Fixes

  • JSONPath parser recursion limit failures now raise JSONPathRecursionError, preserving the original RecursionError as the cause. JSONPathRecursionError now also subclasses RecursionError, allowing existing except RecursionError handlers to continue working.

Version 2.2.0

Choose a tag to compare

@jg-rp jg-rp released this 05 Jul 08:26

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) and JSONPatch.patched(data). patched() is a non-mutating form of JSONPatch application. It always performs a deep copy of data and returns the patched copy. See #131.

Version 2.1.0

Choose a tag to compare

@jg-rp jg-rp released this 26 Jun 06:27

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

Choose a tag to compare

@jg-rp jg-rp released this 10 Jan 07:54

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 standard match and search functions. See #124.

Version 2.0.1

Choose a tag to compare

@jg-rp jg-rp released this 13 Sep 08:02

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 JSONPointerIndexError when 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_index to a suitably negative integer, like JSONPointer.min_int_index = -(2**53) + 1.

    See #116.

  • Fixed the JSON Patch add operation.

    Previously, a JSONPatchError was 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

Choose a tag to compare

@jg-rp jg-rp released this 09 Sep 13:11

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.
  • Filter expressions - float literals must follow the RFC.
    • .1 is now invalid (use 0.1)
    • 1. is now invalid (use 1.0)
  • Slice selectors - indexes and steps must follow the RFC.
    • Leading zeros and negative zero are no longer valid and raise JSONPathSyntaxError.
  • 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. Returns True if both arguments are strings and prefix is a prefix of value. 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, debug and thread_safe arguments to jsonpath.function_extensions.Match and jsonpath.function_extensions.Search constructors.

JSONPath features

  • Added the Keys filter selector.
  • Added the Singular query selector.
  • Match and search function extensions now use the regex package (if installed) instead of re. See optional dependencies.
  • Added the strict argument to all convenience functions, the CLI and the JSONPathEnvironment constructor. When strict=True, all non-standard extensions and relaxed parsing rules are disabled.
  • Added class variable JSONPathEnvironment.max_recursion_depth to control the maximum recursion depth of descendant segments.
  • Improved exception messages (prettier, more informative).

Python API changes

  • Renamed class variable JSONPathEnvironment.fake_root_token to JSONPathEnvironment.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

Choose a tag to compare

@jg-rp jg-rp released this 15 Aug 07:36

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

Choose a tag to compare

@jg-rp jg-rp released this 22 Jun 08:09

Fixes

  • Fixed the non-standard JSON Patch operation, addap. Previously it was behaving like addne. See #81.
  • Fixed JSON Patch ops that operate on mappings and have a target that looks like an int. We now ensure the target is a string. See #82.

Version 1.3.0

Choose a tag to compare

@jg-rp jg-rp released this 04 Feb 08:41

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.NodeList is now re-exported as jsonpath.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

Choose a tag to compare

@jg-rp jg-rp released this 09 Dec 15:07

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.