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
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
Atomic literals
Object constructors
Array constructors
Composing constructors
Basic operations
Construction of sequences
Comma operator
Range operator
Parenthesized expression
Arithmetics
String concatenation
Comparison
Logics
Function Calls
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. Expr
24. RangeExpr
25. ParenthesizedExpr
26. AdditiveExpr
27. MultiplicativeExpr
28. UnaryExpr
29. StringConcatExpr
30. ComparisonExpr
31. OrExpr
32. AndExpr
33. NotExpr
34. QuantifiedExpr
35. FunctionCall
36. PostfixExpr
37. ObjectLookup
38. ArrayLookup
39. ArrayUnboxing
40. Predicate
41. ContextItemExpr
42. IfExpr
43. SwitchExpr
44. TryCatchExpr
45. FLWORExpr
46. ForClause
47. WhereClause
48. OrderByClause
49. GroupByClause
50. LetClause
51. CountClause
52. SimpleMapExpr
53. ContextItemExpr
54. OrderedExpr
55. UnorderedExpr
56. InstanceofExpr
57. TreatExpr
58. CastableExpr
59. CastExpr
60. TypeswitchExpr
61. CaseClause
62. MainModule
63. Prolog
64. DefaultCollationDecl
65. OrderingModeDecl
66. EmptyOrderDecl
67. DecimalFormatDecl
68. DFPropertyName
69. VarDecl
70. VarDecl
71. Module
72. MainModule
73. LibraryModule
74. ModuleImport

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