Skip to content

Commit 944e74d

Browse files
committed
docs ✏️ shorten more sections
1 parent 103fcd5 commit 944e74d

File tree

1 file changed

+24
-213
lines changed

1 file changed

+24
-213
lines changed

src/json-path/__context__/rfc9535-short.txt

Lines changed: 24 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -958,67 +958,16 @@ Function extensions add filter expression functionality. Each has a unique regis
958958

959959
2.4.1. Type System for Function Expressions
960960

961-
Each parameter and the result of a function extension must have a
962-
declared type.
961+
Function parameters and results have declared types for well-typedness checking:
962+
- ValueType: JSON values or Nothing
963+
- LogicalType: LogicalTrue or LogicalFalse
964+
- NodesType: Nodelists
963965

964-
Declared types enable checking a JSONPath query for well-typedness
965-
independent of any query argument the JSONPath query is applied to.
966-
967-
Table 13 defines the available types in terms of the instances they
968-
contain.
969-
970-
+=============+=============================+
971-
| Type | Instances |
972-
+=============+=============================+
973-
| ValueType | JSON values or Nothing |
974-
+-------------+-----------------------------+
975-
| LogicalType | LogicalTrue or LogicalFalse |
976-
+-------------+-----------------------------+
977-
| NodesType | Nodelists |
978-
+-------------+-----------------------------+
979-
980-
Table 13: Function Extension Type System
981-
982-
Notes:
983-
984-
* The only instances that can be directly represented in JSONPath
985-
syntax are certain JSON values in ValueType expressed as literals
986-
(which, in JSONPath, are limited to primitive values).
987-
988-
* The special result Nothing represents the absence of a JSON value
989-
and is distinct from any JSON value, including null.
990-
991-
* LogicalTrue and LogicalFalse are unrelated to the JSON values
992-
expressed by the literals true and false.
966+
Nothing represents absence of JSON value (distinct from null). LogicalTrue/False are distinct from JSON true/false.
993967

994968
2.4.2. Type Conversion
995969

996-
Just as queries can be used in logical expressions by testing for the
997-
existence of at least one node (Section 2.3.5.2.1), a function
998-
expression of declared type NodesType can be used as a function
999-
argument for a parameter of declared type LogicalType, with the
1000-
equivalent conversion rule:
1001-
1002-
* If the nodelist contains one or more nodes, the conversion result
1003-
is LogicalTrue.
1004-
1005-
* If the nodelist is empty, the conversion result is LogicalFalse.
1006-
1007-
Notes:
1008-
1009-
* Extraction of a value from a nodelist can be performed in several
1010-
ways, so an implicit conversion from NodesType to ValueType may be
1011-
surprising and has therefore not been defined.
1012-
1013-
* A function expression with a declared type of NodesType can
1014-
indirectly be used as an argument for a parameter of declared type
1015-
ValueType by wrapping the expression in a call to a function
1016-
extension, such as value() (see Section 2.4.8), that takes a
1017-
parameter of type NodesType and returns a result of type
1018-
ValueType.
1019-
1020-
The well-typedness of function expressions can now be defined in
1021-
terms of this type system.
970+
NodesType→LogicalType conversion: non-empty nodelist→LogicalTrue, empty→LogicalFalse. No implicit NodesType→ValueType conversion (use value() function).
1022971

1023972
2.4.3. Well-Typedness of Function Expressions
1024973

@@ -1037,187 +986,49 @@ Function expressions must be well-typed:
1037986

1038987
2.4.4. length() Function Extension
1039988

1040-
Parameters:
1041-
1. ValueType
1042-
1043-
Result: ValueType (unsigned integer or Nothing)
1044-
1045-
The length() function extension provides a way to compute the length
1046-
of a value and make that available for further processing in the
1047-
filter expression:
1048-
1049-
$[?length(@.authors) >= 5]
1050-
1051-
Its only argument is an instance of ValueType (possibly taken from a
1052-
singular query, as in the example above). The result is also an
1053-
instance of ValueType: an unsigned integer or the special result
1054-
Nothing.
1055-
1056-
* If the argument value is a string, the result is the number of
1057-
Unicode scalar values in the string.
989+
Parameters: ValueType → Result: ValueType (unsigned integer or Nothing)
1058990

1059-
* If the argument value is an array, the result is the number of
1060-
elements in the array.
991+
Returns length of strings (Unicode scalar values), arrays (elements), objects (members). Other types return Nothing.
1061992

1062-
* If the argument value is an object, the result is the number of
1063-
members in the object.
1064-
1065-
* For any other argument value, the result is the special result
1066-
Nothing.
993+
Example: $[?length(@.authors) >= 5]
1067994

1068995
2.4.5. count() Function Extension
1069996

1070-
Parameters:
1071-
1. NodesType
1072-
1073-
Result: ValueType (unsigned integer)
1074-
1075-
The count() function extension provides a way to obtain the number of
1076-
nodes in a nodelist and make that available for further processing in
1077-
the filter expression:
1078-
1079-
$[?count(@.*.author) >= 5]
997+
Parameters: NodesType → Result: ValueType (unsigned integer)
1080998

1081-
Its only argument is a nodelist. The result is a value (an unsigned
1082-
integer) that gives the number of nodes in the nodelist.
999+
Returns number of nodes in nodelist. No deduplication performed.
10831000

1084-
Notes:
1085-
1086-
* There is no deduplication of the nodelist.
1087-
1088-
* The number of nodes in the nodelist is counted independent of
1089-
their values or any children they may have, e.g., the count of a
1090-
non-empty singular nodelist such as count(@) is always 1.
1001+
Example: $[?count(@.*.author) >= 5]
10911002

10921003
2.4.6. match() Function Extension
10931004

1094-
Parameters:
1095-
1. ValueType (string)
1096-
1097-
2. ValueType (string conforming to [RFC9485])
1098-
1099-
Result: LogicalType
1005+
Parameters: ValueType (string), ValueType (I-Regexp string) → Result: LogicalType
11001006

1101-
The match() function extension provides a way to check whether (the
1102-
entirety of; see Section 2.4.7) a given string matches a given
1103-
regular expression, which is in the form described in [RFC9485].
1007+
Tests if entire string matches I-Regexp pattern. Returns LogicalFalse for invalid inputs.
11041008

1105-
$[?match(@.date, "1974-05-..")]
1106-
1107-
Its arguments are instances of ValueType (possibly taken from a
1108-
singular query, as for the first argument in the example above). If
1109-
the first argument is not a string or the second argument is not a
1110-
string conforming to [RFC9485], the result is LogicalFalse.
1111-
Otherwise, the string that is the first argument is matched against
1112-
the I-Regexp contained in the string that is the second argument; the
1113-
result is LogicalTrue if the string matches the I-Regexp and is
1114-
LogicalFalse otherwise.
1009+
Example: $[?match(@.date, "1974-05-..")]
11151010

11161011
2.4.7. search() Function Extension
11171012

1118-
Parameters:
1119-
1. ValueType (string)
1120-
1121-
2. ValueType (string conforming to [RFC9485])
1122-
1123-
Result: LogicalType
1013+
Parameters: ValueType (string), ValueType (I-Regexp string) → Result: LogicalType
11241014

1125-
The search() function extension provides a way to check whether a
1126-
given string contains a substring that matches a given regular
1127-
expression, which is in the form described in [RFC9485].
1015+
Tests if string contains substring matching I-Regexp pattern. Returns LogicalFalse for invalid inputs.
11281016

1129-
$[?search(@.author, "[BR]ob")]
1130-
1131-
Its arguments are instances of ValueType (possibly taken from a
1132-
singular query, as for the first argument in the example above). If
1133-
the first argument is not a string or the second argument is not a
1134-
string conforming to [RFC9485], the result is LogicalFalse.
1135-
Otherwise, the string that is the first argument is searched for a
1136-
substring that matches the I-Regexp contained in the string that is
1137-
the second argument; the result is LogicalTrue if at least one such
1138-
substring exists and is LogicalFalse otherwise.
1017+
Example: $[?search(@.author, "[BR]ob")]
11391018

11401019
2.4.8. value() Function Extension
11411020

1142-
Parameters:
1143-
1. NodesType
1144-
1145-
Result: ValueType
1021+
Parameters: NodesType → Result: ValueType
11461022

1147-
The value() function extension provides a way to convert an instance
1148-
of NodesType to a value and make that available for further
1149-
processing in the filter expression:
1023+
Converts nodelist to value: single node→node value, empty/multiple→Nothing. Singular queries don't need this function.
11501024

1151-
$[?value(@..color) == "red"]
1152-
1153-
Its only argument is an instance of NodesType (possibly taken from a
1154-
filter-query, as in the example above). The result is an instance of
1155-
ValueType.
1156-
1157-
* If the argument contains a single node, the result is the value of
1158-
the node.
1159-
1160-
* If the argument is the empty nodelist or contains multiple nodes,
1161-
the result is Nothing.
1162-
1163-
Note: A singular query may be used anywhere where a ValueType is
1164-
expected, so there is no need to use the value() function extension
1165-
with a singular query.
1025+
Example: $[?value(@..color) == "red"]
11661026

11671027
2.4.9. Examples
11681028

1169-
+======================+==========================================+
1170-
| Query | Comment |
1171-
+======================+==========================================+
1172-
| $[?length(@) < 3] | well-typed |
1173-
+----------------------+------------------------------------------+
1174-
| $[?length(@.*) < 3] | not well-typed since @.* is a non- |
1175-
| | singular query |
1176-
+----------------------+------------------------------------------+
1177-
| $[?count(@.*) == 1] | well-typed |
1178-
+----------------------+------------------------------------------+
1179-
| $[?count(1) == 1] | not well-typed since 1 is not a query or |
1180-
| | function expression |
1181-
+----------------------+------------------------------------------+
1182-
| $[?count(foo(@.*)) | well-typed, where foo() is a function |
1183-
| == 1] | extension with a parameter of type |
1184-
| | NodesType and result type NodesType |
1185-
+----------------------+------------------------------------------+
1186-
| $[?match(@.timezone, | well-typed |
1187-
| 'Europe/.*')] | |
1188-
+----------------------+------------------------------------------+
1189-
| $[?match(@.timezone, | not well-typed as LogicalType may not be |
1190-
| 'Europe/.*') == | used in comparisons |
1191-
| true] | |
1192-
+----------------------+------------------------------------------+
1193-
| $[?value(@..color) | well-typed |
1194-
| == "red"] | |
1195-
+----------------------+------------------------------------------+
1196-
| $[?value(@..color)] | not well-typed as ValueType may not be |
1197-
| | used in a test expression |
1198-
+----------------------+------------------------------------------+
1199-
| $[?bar(@.a)] | well-typed for any function bar() with a |
1200-
| | parameter of any declared type and |
1201-
| | result type LogicalType |
1202-
+----------------------+------------------------------------------+
1203-
| $[?bnl(@.*)] | well-typed for any function bnl() with a |
1204-
| | parameter of declared type NodesType or |
1205-
| | LogicalType and result type LogicalType |
1206-
+----------------------+------------------------------------------+
1207-
| $[?blt(1==1)] | well-typed, where blt() is a function |
1208-
| | with a parameter of declared type |
1209-
| | LogicalType and result type LogicalType |
1210-
+----------------------+------------------------------------------+
1211-
| $[?blt(1)] | not well-typed for the same function |
1212-
| | blt(), as 1 is not a query, logical- |
1213-
| | expr, or function expression |
1214-
+----------------------+------------------------------------------+
1215-
| $[?bal(1)] | well-typed, where bal() is a function |
1216-
| | with a parameter of declared type |
1217-
| | ValueType and result type LogicalType |
1218-
+----------------------+------------------------------------------+
1219-
1220-
Table 14: Function Expression Examples
1029+
Well-typed: $[?length(@) < 3], $[?count(@.*) == 1], $[?match(@.timezone, 'Europe/.*')], $[?value(@..color) == "red"]
1030+
1031+
Not well-typed: $[?length(@.*) < 3] (non-singular query), $[?count(1) == 1] (literal instead of query), $[?match(@.timezone, 'Europe/.*') == true] (LogicalType in comparison), $[?value(@..color)] (ValueType in test expression)
12211032

12221033
2.5. Segments
12231034

0 commit comments

Comments
 (0)