Skip to content

v0.9.10 - A major reworking of the classic JSONPath

Choose a tag to compare

@brunerd brunerd released this 11 Oct 18:45
· 43 commits to main since this release
cc2d6dd

An extensive reworking of the original Javascript JSONPath engine by Stefan Gössner ("Goessner"), but keeping with ES5 syntax and functions for broad compatibility. Here are some highlights:

  • It has a completely new "normalize" engine for better syntax enforcement: Unquoted key names are no longer allowed most notably but more importantly it now has better handling of complex expressions.
  • Property names containing ], ;, or that are syntactically identical to expressions like a single * or a filter expression (key) are all fully accessible with no confusion in the normalize engine.
  • Key names containing Unicode characters may also be accessed using \u Unicode escape sequence. Property names containing \u0000-\u001f and \u007f, while very odd, will be properly \u escaped if PATH or PATH_DOTTED output if used for the value of the resultType property, additionally \u encoding for all Unicode characters in a property name can be enabled by setting the escapeUnicode property
  • Unions can now handle key names with mixed quoting styles (single and double), multiple filter and script expressions, as well as multiple slice expressions.
  • Slices now allow for negative step (reverse an array), negative array indices (truncation), as well as script expressions for creative array sampling (e.g. division)
  • Strings can now be accessed by singular or multiple array indices for discreet character output as an array. They can also be sliced and maintain their stringiness.
  • resulType:"PATH" still outputs bracket style paths but now defaults to double quotes with single quotes being an option via the singleQuoteKeys property. Additional resultType options have been added: PATH_DOTTED for dot style paths (when possible) and PATH_JSONPOINTER for RFC 6901 JSON Pointer output
  • Script and filter expressions now check for disallowed function invocations and will terminate execution if functions other than test() match() and exec() are found. This maintains compatibility with regex queries of the original however these methods should not need to be called now since we have the =~ Ruby style regex operator that invokes test() behind the scenes; still, it's nice to have.
  • == and != operators in script and filter expressions will evaluate as === and !== respectively, enforcing strict equality to ensure unexpected Javascript type coercion does not occur.
  • The addition of the [-] expression, borrowed from JSON Pointer to represent the next array index after the last. While this of no use to search and retrieval (it is always non-existent), it is beneficial for JSON creation tools to be able to add to the end of an array.