You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Filter selectors are used to iterate over the elements or members of
594
-
structured values, i.e., JSON arrays and objects. The structured
595
-
values are identified in the nodelist offered by the child or
596
-
descendant segment using the filter selector.
597
-
598
-
For each iteration (element/member), a logical expression (the
599
-
_filter expression_) is evaluated, which decides whether the node of
600
-
the element/member is selected. (While a logical expression
601
-
evaluates to what mathematically is a Boolean value, this
602
-
specification uses the term _logical_ to maintain a distinction from
603
-
the Boolean values that JSON can represent.)
604
-
605
-
During the iteration process, the filter expression receives the node
606
-
of each array element or object member value of the structured value
607
-
being filtered; this element or member value is then known as the
608
-
_current node_.
609
-
610
-
The current node can be used as the start of one or more JSONPath
611
-
queries in subexpressions of the filter expression, notated via the
612
-
current-node-identifier @. Each JSONPath query can be used either for
613
-
testing existence of a result of the query, for obtaining a specific
614
-
JSON value resulting from that query that can then be used in a
615
-
comparison, or as a _function argument_.
616
-
617
-
Filter selectors may use function extensions, which are covered in
618
-
Section 2.4. Within the logical expression for a filter selector,
619
-
function expressions can be used to operate on nodelists and values.
620
-
The set of available functions is extensible, with a number of
621
-
functions predefined (see Section 2.4) and the ability to register
622
-
further functions provided by the "Function Extensions" subregistry
623
-
(Section 3.2). When a function is defined, it is given a unique
624
-
name, and its return value and each of its parameters are given a
625
-
_declared type_. The type system is limited in scope; its purpose is
626
-
to express restrictions that, without functions, are implicit in the
627
-
grammar of filter expressions. The type system also guides
628
-
conversions (Section 2.4.2) that mimic the way different kinds of
629
-
expressions are handled in the grammar when function expressions are
630
-
not in use.
570
+
Filter selectors iterate over array elements or object members, evaluating a logical expression for each to decide selection. The current node (@) represents each element/member being tested. Supports function extensions with declared types for parameters and results.
631
571
632
572
2.3.5.1. Syntax
633
573
634
-
The filter selector has the form ?<logical-expr>.
574
+
Filter selector: ?<logical-expr>. Supports Boolean operators (||, &&, !), comparisons (==, !=, <, <=, >, >=), existence tests, and function expressions. Current node accessible via @.
635
575
636
576
filter-selector = "?" S logical-expr
637
577
638
-
As the filter expression is composed of constituents free of side
639
-
effects, the order of evaluation does not need to be (and is not)
640
-
defined. Similarly, for conjunction (&&) and disjunction (||)
641
-
(defined later), both a short-circuiting and a fully evaluating
642
-
implementation will lead to the same result; both implementation
643
-
strategies are therefore valid.
644
-
645
-
The current node is accessible via the current node identifier @.
646
-
This identifier addresses the current node of the filter-selector
647
-
that is directly enclosing the identifier. Note: Within nested
648
-
filter-selectors, there is no syntax to address the current node of
649
-
any other than the directly enclosing filter-selector (i.e., of
650
-
filter-selectors enclosing the filter-selector that is directly
651
-
enclosing the identifier).
652
-
653
-
Logical expressions offer the usual Boolean operators (|| for OR, &&
654
-
for AND, and ! for NOT). They have the normal semantics of Boolean
655
-
algebra and obey its laws (for example, see [BOOLEAN-LAWS]).
656
-
Parentheses MAY be used within logical-expr for grouping.
657
-
658
-
It is not required that logical-expr consist of a parenthesized
659
-
expression (which was required in [JSONPath-orig]), although it can
660
-
be, and the semantics are the same as without the parentheses.
661
-
662
578
logical-expr = logical-or-expr
663
579
logical-or-expr = logical-and-expr *(S "||" S logical-and-expr)
664
-
; disjunction
665
-
; binds less tightly than conjunction
666
580
logical-and-expr = basic-expr *(S "&&" S basic-expr)
This section defines the extension point and some function extensions
1073
-
that use this extension point. While these mechanisms are designed
1074
-
to use the extension point, they are an integral part of the JSONPath
1075
-
specification and are expected to be implemented like any other
1076
-
integral part of this specification.
1077
-
1078
-
A function extension defines a registered name (see Section 3.2) that
1079
-
can be applied to a sequence of zero or more arguments, producing a
1080
-
result. Each registered function name is unique.
1081
-
1082
-
A function extension MUST be defined such that its evaluation is free
1083
-
of side effects, i.e., all possible orders of evaluation and choices
1084
-
of short-circuiting or full evaluation of an expression containing it
1085
-
MUST lead to the same result. (Note: Memoization or logging are not
1086
-
side effects in this sense as they are visible at the implementation
1087
-
level only -- they do not influence the result of the evaluation.)
945
+
Function extensions add filter expression functionality. Each has a unique registered name, takes arguments, produces results, and must be side-effect free.
0 commit comments