The complete reference



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

Table of Contents

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
Construction of items
Booleans and null
Other atomic values
Inline function expression
Named function reference
Manipulating atomic values
String concatenation
Manipulating sequences
Comma operator
Range operator
Parenthesized expression
Calling functions
Static function calls
Dynamic function calls
Partial application
Navigating objects
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
Variable references
Composing FLWOR expressions
Ordered and Unordered expressions
Expressions dealing with types
Instance-of expressions
Treat expressions
Castable expressions
Cast expressions
Typeswitch expressions
Default collation
Default ordering mode
Default ordering behaviour for empty sequences
Default decimal format
Global variables
Function Library
JSON specific functions.
Functions taken from XQuery
Equality and identity
Sequences vs. Arrays
Null vs. empty sequence
Open Issues
Revision History

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. AdditiveExpr
28. MultiplicativeExpr
29. UnaryExpr
30. StringConcatExpr
31. ComparisonExpr
32. OrExpr
33. AndExpr
34. NotExpr
35. QuantifiedExpr
36. Expr
37. RangeExpr
38. ParenthesizedExpr
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. SwitchCaseClause
52. TryCatchExpr
53. FLWORExpr
54. ForClause
55. WhereClause
56. OrderByClause
57. GroupByClause
58. LetClause
59. CountClause
60. SimpleMapExpr
61. ContextItemExpr
62. OrderedExpr
63. UnorderedExpr
64. InstanceofExpr
65. TreatExpr
66. CastableExpr
67. CastExpr
68. TypeswitchExpr
69. CaseClause
70. MainModule
71. Prolog
72. DefaultCollationDecl
73. OrderingModeDecl
74. EmptyOrderDecl
75. DecimalFormatDecl
76. DFPropertyName
77. VarDecl
78. VarDecl
79. Module
80. MainModule
81. LibraryModule
82. 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. Integer literals
17. Decimal literals
18. Double literals
19. String literals
20. String literals with escaping
21. String literals with Unicode character escaping
22. String literals with a nested quote
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. Object constructors with needed quotes around the key
36. Empty array constructors
37. Array constructors
38. Nested array constructors
39. Inline function expression
40. Named function reference
41. Basic arithmetic operations with precedence override
42. Using basic operations with dates.
43. Sequence of more than one number in an addition
44. Null in an addition
45. Basic arithmetic operations with an empty sequence
46. String concatenation
47. String concatenation with the empty sequence
48. Equality and non-equality comparison with null
49. Ordering comparison with null
50. Equality comparison
51. Comparisons with a type mismatch
52. Comparison with the empty sequence
53. Logics with booleans
54. Logics with comparing operands
55. Conversion of the empty sequence to false
56. Conversion of null to false
57. Conversion of a string to true
58. Conversion of a number to false
59. Conversion of an object to a boolean (not implemented in Zorba at this point)
60. Error upon conversion of a sequence of more than one item, not beginning with a JSON item, to a boolean
61. Non-determinism in presence of errors.
62. Universal quantifier
63. Existential quantifier on several variables
64. Existential quantifier with type checking
65. Comma
66. Comma
67. Range operator
68. Range operator with the empty sequence
69. Range operator with a type inconsistency
70. Empty sequence
71. A builtin function call.
72. A builtin function call.
73. A type error in a function call.
74. A dynamic function call.
75. A dynamic function call with signature
76. A partial application.
77. Object lookup
78. Lookup on a single-object collection.
79. Object lookup with an iteration on several objects
80. Object lookup with an iteration on a collection
81. Object lookup on a mixed sequence
82. Quotes for object lookup
83. Object lookup with a nested expression
84. Object lookup with a nested expression
85. Object lookup with a nested expression
86. Object lookup with a variable
87. Array lookup
88. Array lookup after an object lookup
89. Array lookup with an iteration on several arrays
90. Array lookup with an iteration on a collection
91. Array lookup on a mixed sequence
92. Array lookup with a right-hand-side expression
93. Extracting all items from an array
94. Extracting all items from arrays in a mixed sequence
95. Predicate expression
96. Predicate 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 conditional expression
106. A switch expression
107. A switch expression
108. A switch expression
109. A switch expression
110. A switch expression
111. A try catch expression
112. A try catch expression
113. A try catch expression
114. A for clause.
115. Two for clauses.
116. A for clause.
117. A for clause.
118. A for clause.
119. A for clause.
120. A join
121. A join
122. A where clause.
123. An order by clause.
124. An order by clause.
125. An order by clause.
126. An order by clause.
127. Use of a collation in 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. An order by clause.
135. A simple map
136. An equivalent query
137. Nested FLWORs
138. An unordered expression.
139. An ordered 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. Instance of 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. Treat as expression
154. Castable as expression
155. Castable as expression
156. Castable as expression
157. Castable as expression
158. Castable as expression
159. Castable 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. Cast as expression
167. Typeswitch expression
168. Typeswitch expression
169. Typeswitch expression
170. Global variable
171. Global variable
172. Global variable with a type
173. An external global variable
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. An external global variable with a default value
179. A library module
180. An importing main module
181. Getting all distinct key names in the supplied objects, ignoring non-objects.
182. Retrieving all Pairs from an Object:
183. Retrieving the members of all supplied arrays, ignoring non-arrays.
184. Parsing a JSON document
185. Parsing multiple, whitespace-separated JSON documents
186. Retrieving the size of an array
187. Accessing all descendant pairs
188. Projecting an object 1
189. Projecting an object 2
190. Removing keys from an object (not implemented yet)
191. Logical comparison of two atomics
192. Logical comparison of two atomics
193. Logical comparison of two atomics
194. Logical comparison of two atomics
195. Logical comparison of two JSON items
196. Logical comparison of two JSON items
197. Flat sequences
198. Nesting arrays
199. Singleton sequences
200. Singleton sequences
201. count() on an array
202. count() on a sequence
203. Members of an array
204. Members of an sequence
205. Converting an array to a sequence
206. Converting a sequence to an array
207. Null values in an array
208. Null values in an object
209. Null values in a sequence
210. Automatic conversion to null.
211. Empty sequence in an arithmetic operation.
212. Null in an arithmetic operation.
213. Null and empty sequence in an arithmetic operation.
214. Empty sequence in a comparison.
215. Null in a comparison.
216. Null in a comparison.
217. Null and the empty sequence in a comparison.
218. Null and the empty sequence in a comparison.