Skip to content

Releases: hiltontj/serde_json_path

v0.7.1

03 Nov 21:50
485edcd
Compare
Choose a tag to compare

0.7.1 (3 November 2024)

  • internal: update serde_json to the latest version (#107)
  • fixed: edge case where . in regexes for match and search functions was matching \r\n properly (#92)
  • breaking: added regex feature flag that gates regex functions match and search (#93, thanks @LucasPickering)
    • Feature is enabled by default, but if you have default-features = false you'll need to explicitly add it to retain access to these functions
  • breaking(serde_json_path_core): ensure integers used as indices are within the valid range for I-JSON (#98)
  • internal: remove use of once_cell and use specific versions for crate dependencies (#105)

v0.6.7

03 Mar 22:44
a9f8f08
Compare
Choose a tag to compare

0.6.7 (3 March 2024)

  • testing: support tests for non-determinism in compliance test suite (#85)
  • fixed: bug preventing registered functions from being used as arguments to other functions (#84)

v0.6.6

24 Feb 03:55
f2004fc
Compare
Choose a tag to compare

0.6.6 (23 February 2024)

  • docs: update links to refer to RFC 9535 (#81)

v0.6.5

03 Feb 16:34
bd507d4
Compare
Choose a tag to compare

0.6.5 (3 February 2024)

Added: NormalizedPath and PathElement types (#78)

The NormalizedPath struct represents the location of a node within a JSON object. Its representation is like so:

pub struct NormalizedPath<'a>(Vec<PathElement<'a>);

pub enum PathElement<'a> {
    Name(&'a str),
    Index(usize),
}

Several methods were included to interact with a NormalizedPath, e.g., first, last, get, iter, etc., but notably there is a to_json_pointer method, which allows direct conversion to a JSON Pointer to be used with the serde_json::Value::pointer or serde_json::Value::pointer_mut methods.

The new PathElement type also comes equipped with several methods, and both it and NormalizedPath have eagerly implemented traits from the standard library / serde to help improve interoperability.

Added: LocatedNodeList and LocatedNode types (#78)

The LocatedNodeList struct was built to have a similar API surface to the NodeList struct, but includes additional methods that give access to the location of each node produced by the original query. For example, it has the locations and nodes methods to provide dedicated iterators over locations or nodes, respectively, but also provides the iter method to iterate over the location/node pairs. Here is an example:

use serde_json::{json, Value};
use serde_json_path::JsonPath;
let value = json!({"foo": {"bar": 1, "baz": 2}});
let path = JsonPath::parse("$.foo.*")?;
let query = path.query_located(&value);
let nodes: Vec<&Value> = query.nodes().collect();
assert_eq!(nodes, vec![1, 2]);
let locs: Vec<String> = query
    .locations()
    .map(|loc| loc.to_string())
    .collect();
assert_eq!(locs, ["$['foo']['bar']", "$['foo']['baz']"]);

The location/node pairs are represented by the LocatedNode type.

The LocatedNodeList provides one unique bit of functionality over NodeList: deduplication of the query results, via the LocatedNodeList::dedup and LocatedNodeList::dedup_in_place methods.

Other Changes

  • internal: address new clippy lints in Rust 1.75 (#75)
  • internal: address new clippy lints in Rust 1.74 (#70)
  • internal: code clean-up (#72)

v0.6.4

09 Nov 19:58
f144e6e
Compare
Choose a tag to compare

0.6.4 (9 November 2023)

  • added: is_empty, is_more_than_one, and as_more_than_one methods to ExactlyOneError (#65)
  • fixed: allow whitespace before dot-name selectors (#67)
  • fixed: ensure that the check == -0 in filters works as expected (#67)

v0.6.3

17 Sep 18:46
51eec54
Compare
Choose a tag to compare

0.6.3 (17 September 2023)

  • documentation: Add line describing Descendant Operator (#53)
  • documentation: Improve example in Filter Selector section of main docs (#54)
  • documentation: Improve examples in Slice Slector section of main docs (#55)
  • documentation: Other improvements to documentation (#56)
  • fixed: Formulate the regex used by the match function to correctly handle regular expressions with leading or trailing | characters (#61)

v0.6.2

13 Jul 11:16
c7f2315
Compare
Choose a tag to compare

0.6.2 (13 July 2023)

  • fixed: Fixed an issue in the evaluation of SingularQuerys that was producing false positive query results when relative singular queries, e.g., @.bar, were being used as comparables in a filter, e.g., $.foo[?(@.bar == 'baz')] (#50)

v0.6.1

06 Jul 12:17
50fbe43
Compare
Choose a tag to compare

0.6.1 (5 July 2023)

  • documentation: Updated links to JSONPath specification to latest version (base 14) #43
  • fixed: Support newline characters in query strings where previously they were not being supported #44

v0.6.0

03 Apr 02:13
036881c
Compare
Choose a tag to compare

0.6.0 (2 April 2023)

Function Extensions (#32)

This release introduces the implementation of Function Extensions in serde_json_path.

This release ships with support for the standard built-in functions that are part of the base JSONPath specification:

  • length
  • count
  • match
  • search
  • value

These can now be used in your JSONPath query filter selectors, and are defined in the crate documentation
in the functions module.

In addition, the #[function] attribute macro was introduced to enable users of serde_json_path to define
their own custom functions for use in their JSONPath queries.

The functions module (added)

In addition to the documentation/definitions for built-in functions, the functions module includes three new types:

  • ValueType
  • NodesType
  • LogicalType

These reflect the type system defined in the JSONPath spec. Each is available through the public API, to be used in custom
function definitions, along with the #[function] attribute macro.

The #[function] attribute macro (added)

A new attribute macro: #[function] was introduced to allow users of serde_json_path to define their
own custom functions for use in their JSONPath queries.

Along with the new types introduced by the functions module, it can be used like so:

use serde_json_path::functions::{NodesType, ValueType};

/// A function that takes a node list, and optionally produces the first element as
/// a value, if there are any elements in the list.
#[serde_json_path::function]
fn first(nodes: NodesType) -> ValueType {
    match nodes.first() {
        Some(v) => ValueType::Node(v),
        None => ValueType::Nothing,
    }
}

Which will then allow you to use a first function in your JSONPath queries:

$[? first(@.*) > 5 ]

Usage of first in you JSONPath queries, like any of the built-in functions, will be validated at parse-time.

The #[function] macro is gated behind the functions feature, which is enabled by default.

Functions defined using the #[function] macro will override any of the built-in functions that are part
of the standard, e.g., length, count, etc.

Changed the Error type (breaking)

The Error type was renamed to ParseError and was updated to have more concise error messages. It was
refactored internally to better support future improvements to the parser. It is now a struct, vs. an enum,
with a private implementation, and two core APIs:

  • message(): the parser error message
  • position(): indicate where the parser error was encountered in the JSONPath query string

This gives far more concise errors than the pre-existing usage of nom's built-in VerboseError type.
However, for now, this leads to somewhat of a trade-off, in that errors that are not specially handled
by the parser will present as just "parser error" with a position. Over time, the objective is to
isolate cases where specific errors can be propagated up, and give better error messages.

Repository switched to a workspace

With this release, serde_json_path is split into four separate crates:

  • serde_json_path
  • serde_json_path_macros
  • serde_json_path_macros_internal
  • serde_json_path_core

serde_json_path is still the entry point for general consumption. It still contains some of the key
components of the API, e.g., JsonPath, JsonPathExt, and Error, as well as the entire parser module.
However, many of the core types used to represent the JSONPath model, as defined in the specification,
were moved into serde_json_path_core.

This split was done to accommodate the new #[function] attribute macro, which is defined within the
serde_json_path_macros/macros_internal crates, and discussed below.

Other Changes

  • added: updated to latest version of CTS to ensure compliance #33
  • added: implement Eq for JsonPath #34
  • breaking:: Changed the name of Error type to ParseError #36