~davidagraf/zorba/trace_without_debug_info

« back to all changes in this revision

Viewing changes to modules/org/jsoniq/www/functions.xq

  • Committer: David Graf
  • Date: 2012-06-27 07:20:59 UTC
  • mfrom: (10869.1.25 zorba)
  • Revision ID: davidagraf@gmail.com-20120627072059-723duu6vsbqu60ax
merged trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
xquery version "1.0";
 
2
 
 
3
(:
 
4
 : Copyright 2006-2012 The FLWOR Foundation.
 
5
 :
 
6
 : Licensed under the Apache License, Version 2.0 (the "License");
 
7
 : you may not use this file except in compliance with the License.
 
8
 : You may obtain a copy of the License at
 
9
 :
 
10
 : http://www.apache.org/licenses/LICENSE-2.0
 
11
 :
 
12
 : Unless required by applicable law or agreed to in writing, software
 
13
 : distributed under the License is distributed on an "AS IS" BASIS,
 
14
 : WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
15
 : See the License for the specific language governing permissions and
 
16
 : limitations under the License.
 
17
:)
 
18
 
 
19
 
 
20
(:~
 
21
 : This module provides the functions defined by the JSONiq specification,
 
22
 : sections 1.7 (Functions) and 1.10 (Update Primitives). JSONiq extends
 
23
 : the XQuery specification to also deal with JSON data natively. See
 
24
 :
 
25
 :     http://www.jsoniq.org/
 
26
 :
 
27
 : for details.
 
28
 :
 
29
 : This module depends on having the JSONiq feature enabled in Zorba,
 
30
 : i.e., Zorba must be compiled with ZORBA_WITH_JSON.
 
31
 :
 
32
 : @author Markos Zaharioudakis, Matthias Brantner
 
33
 :)
 
34
module namespace jn = "http://www.jsoniq.org/functions";
 
35
 
 
36
import module namespace schema = "http://www.zorba-xquery.com/modules/schema";
 
37
 
 
38
declare namespace jdm = "http://www.jsoniq.org/";
 
39
 
 
40
declare namespace err = "http://www.w3.org/2005/xqt-errors";
 
41
 
 
42
declare namespace ver = "http://www.zorba-xquery.com/options/versioning";
 
43
declare option ver:module-version "1.0";
 
44
 
 
45
 
 
46
(:~
 
47
 : This function has the same semantics as fn:parse-xml(), except that
 
48
 : it parses the string as JSON (not XML), and returns an Object or
 
49
 : Array rather than an XML document.
 
50
 :
 
51
 : @param $j A string containing a valid JSON text.
 
52
 : @return a JSON Object or Array item.
 
53
 :)
 
54
declare function jn:parse-json($j as xs:string) as json-item()? external;
 
55
 
 
56
 
 
57
(:~
 
58
 : Returns the names used in the Pairs of the object. 
 
59
 : The names will be returned in an implementation-defined order
 
60
 :
 
61
 : @param $o A JSON Object.
 
62
 : @return The names of pairs in the object.
 
63
 :)
 
64
declare function jn:keys($o as object()) as xs:string* external;
 
65
 
 
66
 
 
67
(:~
 
68
 : Returns the values of the pairs within a given JSON object.
 
69
 :
 
70
 : @param $o A JSON Object.
 
71
 : @return the value of each pair within the given object.
 
72
 :)
 
73
declare function jn:values($o as object()) as item()* external;
 
74
 
 
75
 
 
76
(:~
 
77
 : Returns the value of a JSON Pair with a given name within a given JSON object.
 
78
 : If no such pair exists in the object, returns the empty sequence.
 
79
 :
 
80
 : @param $o A JSON Object.
 
81
 : @param $name The name of the pair whose value is to be retrieved
 
82
 : @return the value of specified pair within the given object, or the empty sequence.
 
83
 :)
 
84
declare function jn:value($o as object(), $name as xs:string) as item()? external;
 
85
 
 
86
 
 
87
(:~
 
88
 : Creates an object from the specified pairs of another given object. 
 
89
 : Specifically, for each name in $names, if the object $o has a pair with
 
90
 : that name, then a copy of that pair is included in the new object.
 
91
 :
 
92
 : @param $o A JSON Object.
 
93
 : @param $names The names of the pairs to copy out of $o and insert into the new object
 
94
 : @return The new object.
 
95
 :)
 
96
declare function jn:project($o as object(), $names as xs:string*) as object() external;
 
97
 
 
98
(:~
 
99
 : Returns the size of a JSON Object or JSON Array. The size of an Object
 
100
 : is the number of Pairs contained within it; the size of an Array is
 
101
 : the number of members contained within it.
 
102
 :
 
103
 : @param $j A JSON Object or JSON Array.
 
104
 : @return The number of items in $j.
 
105
 : @error jn:JUDY0060 if $j is a JSON Pair.
 
106
 :)
 
107
declare function jn:size($j as json-item()) as xs:integer external;
 
108
 
 
109
 
 
110
(:~
 
111
 : Returns the member of an Array at the specified position (starting from 1).
 
112
 : If the position is out of bounds of the array, returns the empty sequence.
 
113
 :
 
114
 : @param $a A JSON Array.
 
115
 : @param $p The position in the array.
 
116
 : @return The member at the specified position, or empty sequence.
 
117
 :)
 
118
declare function jn:member($o as array(), $p as xs:integer) as item()? external;
 
119
 
 
120
 
 
121
(:~
 
122
 : Returns the members of an Array.
 
123
 :
 
124
 : @param $a A JSON Array.
 
125
 : @return The members of the specified array.
 
126
 :)
 
127
declare function jn:members($o as array()) as item()* external;
 
128
 
 
129
 
 
130
(:~
 
131
 : Recursively "flatten" a JSON Array, by replacing any arrays with their
 
132
 : members. Equivalent to
 
133
 :
 
134
 :   define function jn:flatten($arg as array()) {
 
135
 :     for $value in jn:values($arg)
 
136
 :     return
 
137
 :       if ($value instance of array())
 
138
 :       then jn:flatten($value)
 
139
 :       else $value
 
140
 :   };
 
141
 :
 
142
 : @param $a A JSON Array.
 
143
 : @return The flattened version of $a.
 
144
 :)
 
145
declare function jn:flatten($a as array()) as item()* external;
 
146