Skip to content

Releases: jg-rp/python-jsonpath

Version 1.2.0

05 Aug 07:01
Compare
Choose a tag to compare

Fixes

  • Fixed handling of JSONPath literals in filter expressions. We now raise a JSONPathSyntaxError if a filter expression literal is not part of a comparison, membership or function expression. See jsonpath-compliance-test-suite#81.
  • Fixed parsing of number literals including an exponent. Upper case 'e's are now allowed.
  • Fixed handling of trailing commas in bracketed selection lists. We now raise a JSONPathSyntaxError in such cases.

Compliance

  • Skipped tests for invalid escape sequences. The JSONPath spec is more strict than Python's JSON decoder when it comes to parsing \u escape sequences in string literals. We are adopting a policy of least surprise. The assertion is that most people will expect the JSONPath parser to behave the same as Python's JSON parser. See jsonpath-compliance-test-suite #87.
  • Skipped tests for invalid integer and float literals. Same as above. We are deliberately choosing to match Python's int and float parsing behavior. See jsonpath-compliance-test-suite #89.
  • Skipped tests for incorrect casing true, false and null literals.

Features

  • Allow JSONPath filter expression membership operators (contains and in) to operate on object/mapping data as well as arrays/sequences. See #55.
  • Added a select() method to the JSONPath query iterator interface, generating a projection of each JSONPath match by selecting a subset of its values.
  • Added the query() method to the JSONPath class. Get a query iterator from an already compiled path.
  • Added the addne and addap operations to JSONPatch. addne (add if not exists) is like the standard add operation, but only adds object keys/values if the key does not exist. addap (add or append) is like the standard add operation, but assumes an index of - if the target index can not be resolved.

Version 1.1.1

12 Mar 07:13
Compare
Choose a tag to compare

Fixes

  • Fixed evaluation of JSONPath singular queries when they appear in a logical expression and without a comparison operator. Previously we were evaluating logical expressions with the value held by the single element node list, now we treat such filter queries as existence tests. See #57.

Version 1.1.0

07 Mar 15:44
Compare
Choose a tag to compare

Fixes

  • Fixed logical operator precedence in JSONPath filter expressions. Previously, logical or (||) and logical and (&&) had equal precedence. Now && binds more tightly than ||, as per RFC 9535.
  • Fixed JSONPath bracketed selector list evaluation order. Previously we were iterating nodes for every list item, now we exhaust all matches for the first item before moving on to the next item.

Features

  • Added the "query API", a fluent, chainable interface for manipulating JSONPathMatch iterators (docs, source).

Version 1.0.0

23 Feb 11:50
Compare
Choose a tag to compare

RFC 9535 (JSONPath: Query Expressions for JSON) is now out, replacing the draft IETF JSONPath base.

Breaking Changes

  • The undocumented keys function extension is no longer enabled by default. A new, well-typed keys function 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 the fake_root_token attribute on a JSONPathEnvironment subclass. 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

02 Jan 16:08
51ec96b
Compare
Choose a tag to compare

Breaking Changes

  • Changed the exception raised when attempting to compare a non-singular filter query from JSONPathSyntaxError to JSONPathTypeError.

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

13 Oct 10:52
Compare
Choose a tag to compare

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

08 Oct 15:53
6f9e3be
Compare
Choose a tag to compare

Hot fix

  • Fixed priority of JSONPath lexer rules. Previously, standard short tokens (like * and ?) had a higher priority than environment controlled tokens (like JSONPathEnvironment.keys_selector_token), making it impossible to incorporate short token characters into longer environment-controlled tokens.

Version 0.10.0

02 Oct 07:12
Compare
Choose a tag to compare

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 JSONPathTypeError is raised. This can be disabled in Python JSONPath by setting the well_typed argument to JSONPathEnvironment to False, or using --no-type-checks on 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 to jsonpath.function_extensions.Length.
  • The built-in implementation of the standard value() filter function is now a class and is renamed to jsonpath.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 a JSONPathSyntaxError. See #31.
  • Fixed parsing of JSONPath integer literals that use scientific notation. Previously we raised a JSONPathSyntaxError for literals such as 1e2.
  • Fixed parsing of JSONPath comparison and logical expressions as filter function arguments. Previously we raised a JSONPathSyntaxError if a comparison or logical expression appeared as a filter function argument. Note that none of the built-in, standard filter functions accept arguments of LogicalType.
  • 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

22 Jul 12:42
Compare
Choose a tag to compare

Breaking Changes

  • CompoundJSONPath instances are no longer updated in-place when using .union() and .intersection(). Instead, a new CompoundJSONPath is returned. CompoundJSONPath.paths is now a tuple instead of a list.

Fixes

  • Fixed a bug with the parsing of JSON Pointers. When given an arbitrary string without slashes, JSONPointer would resolve to the document root. The empty string is the only valid pointer that should resolve to the document root. We now raise a JSONPointerError in 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 new JSONPointer (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 to join() (docs).
  • Added JSONPointer.exists(), a method that returns True if a the pointer can be resolved against some data, or False otherwise (docs).
  • Added the RelativeJSONPointer class for building new JSONPointer instances 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 building JSONPointer instances from relative JSON Pointers.
  • Added the unicode_escape argument to JSONPathEnvironment. When True (the default), UTF-16 escaped sequences found in JSONPath string literals will be decoded.

Version 0.8.1

07 Jul 06:20
fc239b9
Compare
Choose a tag to compare

Fixes

  • Fixed the string representation of a JSONPointer when built using JSONPointer.from_parts() and pointing to the document root. See #21.