Record Class JsonPathQuery
java.lang.Object
java.lang.Record
ca.marcusdunn.jsonlens.path.core.query.JsonPathQuery
- Record Components:
segments- the segments, in order
A JSONPath query: the root identifier $ followed by zero or more segments
(RFC 9535, Section 2.1.1).
Each segment operates on the nodelist of the previous segment. The first segment operates on the root node. The parser makes a query from text, and keeps shorthand forms as their bracket equivalents:
| Query text | Segments |
|---|---|
$ |
none |
$.store |
[Child[Name[store]]] |
$.store.* |
[Child[Name[store]], Child[Wildcard[]]] |
$..book[0, 'x'] |
[Descendant[Name[book]], Child[Index[0], Name[x]]] |
JsonPathQuery query = JsonPathParser.standard().parse("$..book[0, 'x']").orElse(null);
Segment segment = query.segments().getFirst();
// segment: Descendant[selectors=[Name[name=book]]]
List<Selector> selectors = query.segments().get(1).selectors();
// selectors: [Index[index=0], Name[name=x]]
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.segments()Returns the value of thesegmentsrecord component.toString()Writes the query as query text in bracket notation.
-
Constructor Details
-
JsonPathQuery
-
-
Method Details
-
toString
Writes the query as query text in bracket notation.
Names and strings are in single quotes, with all necessary escapes. Parentheses occur only where the precedence of the operators makes them necessary. The parser makes an equal query from this text:
// $.store.book[?length(@.title) > 10]['title'], made without the parser. LogicalExpression longTitle = new LogicalExpression.Comparison( new FunctionCall.Value("length", List.of(new FunctionArgument.Value( new SingularQuery(Identifier.CURRENT, List.of(new SingularSegment.Name("title")))))), ComparisonOperator.GREATER, new Literal.NumberLiteral(BigDecimal.TEN)); JsonPathQuery query = new JsonPathQuery(List.of( new Segment.Child(List.of(new Selector.Name("store"))), new Segment.Child(List.of(new Selector.Name("book"))), new Segment.Child(List.of(new Selector.Filter(longTitle))), new Segment.Child(List.of(new Selector.Name("title"))))); String text = query.toString(); // $['store']['book'][?length(@['title']) > 10]['title'] -
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
segments
-