JSONiq

The complete reference

2020-05-12

Abstract

This document provides a complete reference of the core of JSONiq, the JSON query language.


Table of Contents

Introduction
Structure of a JSONiq program.
Main modules
Library modules
Feature matrix
The JSONiq data model
Atomic items
Structured items
Function items
Input datasets
The JSONiq type system
Sequence types
Item types
Atomic types
Structured types
Function types
Expressions
Construction of items
Atomics
Objects
Arrays
Functions
Inline function expression
Named function reference
Basic operations
Construction of sequences
Comma operator
Range operator
Parenthesized expression
Arithmetics
String concatenation
Comparison
Logics
Function Calls
Static function calls
Dynamic function calls
Partial application
Selectors
Object field selector
Array member selector
Sequence predicates
Control flow expressions
Conditional expressions
Switch expressions
Try-catch expressions
FLWOR expressions
For clauses
Where clauses
Order clauses
Group clauses
Let clauses
Count clauses
Map operator
Composing FLWOR expressions
Ordered and Unordered expressions
Expressions dealing with types
Instance-of expressions
Treat expressions
Castable expressions
Cast expressions
Typeswitch expressions
Prologs
Setters.
Default collation
Default ordering mode
Default ordering behaviour for empty sequences
Default decimal format
Global variables
Functions
Modules
Function Library
JSON specific functions.
keys
members
null
parse-json
size
accumulate
descendant-arrays
descendant-objects
descendant-pairs
flatten
intersect
project
remove-keys
values
encode-for-roundtrip
decode-from-roundtrip
Functions taken from XQuery
Equality and identity
Notes
Sequences vs. Arrays
Null vs. empty sequence
Open Issues
Revision History
Index

List of Figures

1. Module
2. MainModule
3. LibraryModule
4. SequenceType
5. ItemType
6. AtomicType
7. StructuredType
8. FunctionType
9. AnyFunctionType
10. TypedFunctionType
11. Literal
12. NumericLiteral
13. IntegerLiteral
14. DecimalLiteral
15. DoubleLiteral
16. StringLiteral
17. BooleanLiteral
18. NullLiteral
19. ObjectConstructor
20. PairConstructor
21. ArrayConstructor
22. Expr
23. FunctionItemExpr
24. InlineFunctionExpr
25. ParamList
26. NamedFunctionRef
27. Expr
28. RangeExpr
29. ParenthesizedExpr
30. AdditiveExpr
31. MultiplicativeExpr
32. UnaryExpr
33. StringConcatExpr
34. ComparisonExpr
35. OrExpr
36. AndExpr
37. NotExpr
38. QuantifiedExpr
39. FunctionCall
40. PostfixExpr
41. ArgumentList
42. Argument
43. PostfixExpr
44. ObjectLookup
45. ArrayLookup
46. ArrayUnboxing
47. Predicate
48. ContextItemExpr
49. IfExpr
50. SwitchExpr
51. TryCatchExpr
52. FLWORExpr
53. ForClause
54. WhereClause
55. OrderByClause
56. GroupByClause
57. LetClause
58. CountClause
59. SimpleMapExpr
60. ContextItemExpr
61. OrderedExpr
62. UnorderedExpr
63. InstanceofExpr
64. TreatExpr
65. CastableExpr
66. CastExpr
67. TypeswitchExpr
68. CaseClause
69. MainModule
70. Prolog
71. DefaultCollationDecl
72. OrderingModeDecl
73. EmptyOrderDecl
74. DecimalFormatDecl
75. DFPropertyName
76. VarDecl
77. VarDecl
78. Module
79. MainModule
80. LibraryModule
81. ModuleImport

List of Tables

1. JSONiq features and the W3C standard

List of Examples

1. A sequence
2. Sequences are flat
3. The empty sequence
4. A sequence of one item
5. Collection 1
6. Collection 2
7. Collection 3
8. Composable array constructors
9. Composable object keys
10. Non-atomic object keys
11. Composable object values
12. Composable object values and automatic conversion
13. Optional pair (not implemented yet in Zorba)
14. Merging object constructor
15. Merging object constructor with a type error
16. String literals
17. String literals with escaping
18. String literals with Unicode character escaping
19. String literals with a nested quote
20. Integer literals
21. Decimal literals
22. Double literals
23. Boolean literals (true)
24. Boolean literals (false)
25. Null literals
26. Empty object constructors
27. Object constructors 1
28. Object constructors 2
29. Object constructors 3
30. Nested object constructors
31. Object constructors with unquoted key 1
32. Object constructors with unquoted key 2
33. Object constructors with unquoted key 3
34. Object constructors with needed quotes around the key
35. Empty array constructors
36. Array constructors
37. Nested array constructors
38. Inline function expression
39. Named function reference
40. Comma
41. Comma
42. Range operator
43. Range operator with the empty sequence
44. Range operator with a type inconsistency
45. Empty sequence
46. Basic arithmetic operations with precedence override
47. Using basic operations with dates.
48. Sequence of more than one number in an addition
49. Null in an addition
50. Basic arithmetic operations with an empty sequence
51. String concatenation
52. String concatenation with the empty sequence
53. Equality comparison
54. Comparisons with a type mismatch
55. Equality and non-equality comparison with null
56. Ordering comparison with null
57. Comparison with the empty sequence
58. Logics with booleans
59. Logics with comparing operands
60. Conversion of the empty sequence to false
61. Conversion of null to false
62. Conversion of a string to true
63. Conversion of a number to false
64. Conversion of an object to a boolean (not implemented in Zorba at this point)
65. Error upon conversion of a sequence of more than one item, not beginning with a JSON item, to a boolean
66. Non-determinism in presence of errors.
67. Universal quantifier
68. Existential quantifier on several variables
69. Existential quantifier with type checking
70. A builtin function call.
71. A builtin function call.
72. A type error in a function call.
73. A dynamic function call.
74. A dynamic function call with signature
75. A partial application.
76. Object lookup
77. Lookup on a single-object collection.
78. Object lookup with an iteration on several objects
79. Object lookup with an iteration on a collection
80. Object lookup on a mixed sequence
81. Quotes for object lookup
82. Object lookup with a nested expression
83. Object lookup with a nested expression
84. Object lookup with a nested expression
85. Object lookup with a variable
86. Array lookup
87. Array lookup after an object lookup
88. Array lookup with an iteration on several arrays
89. Array lookup with an iteration on a collection
90. Array lookup on a mixed sequence
91. Array lookup with a right-hand-side expression
92. Extracting all items from an array
93. Extracting all items from arrays in a mixed sequence
94. Predicate expression
95. Predicate expression
96. A conditional expression
97. A conditional expression
98. A conditional expression
99. A conditional expression
100. A conditional expression
101. A conditional expression
102. A conditional expression
103. A conditional expression
104. A conditional expression
105. A switch expression
106. A switch expression
107. A switch expression
108. A switch expression
109. A switch expression
110. A try catch expression
111. A try catch expression
112. A try catch expression
113. A for clause.
114. Two for clauses.
115. A for clause.
116. A for clause.
117. A for clause.
118. A for clause.
119. A join
120. A join
121. A where clause.
122. An order by clause.
123. An order by clause.
124. An order by clause.
125. An order by clause.
126. Use of a collation in an order by clause.
127. An order by clause.
128. An order by clause.
129. An order by clause.
130. An order by clause.
131. An order by clause.
132. An order by clause.
133. An order by clause.
134. A simple map
135. An equivalent query
136. Nested FLWORs
137. An unordered expression.
138. An ordered expression.
139. Instance of expression
140. Instance of expression
141. Instance of expression
142. Instance of expression
143. Instance of expression
144. Instance of expression
145. Instance of expression
146. Treat as expression
147. Treat as expression
148. Treat as expression
149. Treat as expression
150. Treat as expression
151. Treat as expression
152. Treat as expression
153. Castable as expression
154. Castable as expression
155. Castable as expression
156. Castable as expression
157. Castable as expression
158. Castable as expression
159. Cast as expression
160. Cast as expression
161. Cast as expression
162. Cast as expression
163. Cast as expression
164. Cast as expression
165. Cast as expression
166. Typeswitch expression
167. Typeswitch expression
168. Typeswitch expression
169. Global variable
170. Global variable
171. Global variable with a type
172. An external global variable
173. An external global variable with a default value
174. An external global variable with a default value
175. An external global variable with a default value
176. An external global variable with a default value
177. An external global variable with a default value
178. A library module
179. An importing main module
180. Getting all distinct key names in the supplied objects, ignoring non-objects.
181. Retrieving all Pairs from an Object:
182. Retrieving the members of all supplied arrays, ignoring non-arrays.
183. Parsing a JSON document
184. Parsing multiple, whitespace-separated JSON documents
185. Retrieving the size of an array
186. Accessing all descendant pairs
187. Projecting an object 1
188. Projecting an object 2
189. Removing keys from an object (not implemented yet)
190. Logical comparison of two atomics
191. Logical comparison of two atomics
192. Logical comparison of two atomics
193. Logical comparison of two atomics
194. Logical comparison of two JSON items
195. Logical comparison of two JSON items
196. Flat sequences
197. Nesting arrays
198. Singleton sequences
199. Singleton sequences
200. count() on an array
201. count() on a sequence
202. Members of an array
203. Members of an sequence
204. Converting an array to a sequence
205. Converting a sequence to an array
206. Null values in an array
207. Null values in an object
208. Null values in a sequence
209. Automatic conversion to null.
210. Empty sequence in an arithmetic operation.
211. Null in an arithmetic operation.
212. Null and empty sequence in an arithmetic operation.
213. Empty sequence in a comparison.
214. Null in a comparison.
215. Null in a comparison.
216. Null and the empty sequence in a comparison.
217. Null and the empty sequence in a comparison.