-
Notifications
You must be signed in to change notification settings - Fork 338
Description
Suggestion for an API - JSON.FILTER (#1465)
Syntax
JSON.FILTER key1 [key2 ...] < path > < filter-expression >
Description
The command evaluates the filter-expression against each key's JSON document. If the filter returns non-empty results, the path is fetched from that document; otherwise, null is returned for that key position.
Complexity:
O(M*N) where M is the number of keys and N is the size of the document. Both filter-expression and path are evaluated against each document, with filter evaluation occurring first. When filter or path evaluate to multiple values: O(N1+N2+...+Nm) where m is the number of keys and Ni is the size of the i-th key
Basically a lightweight way of filtering and accessing the JSON tree at different points while adhering to JSONPath.
This allows user to have more complex operations without suffering a big performance impact, so that we can do things such as:
- Filter data at ROOT such as
$.[?($.type == "metadata")]- to fetch any element that is a "metadata" - Allow implementing a
arr.filter((item) => predicate(item))without having to first fetch the entirearr - Allow detaching the filtering aspect of JSONPath from the actual data-fetch, so we can check something along the tree but retrieve a different element