http://jsoniq.org/functions ZC

Module Description
Before using any of the functions below please remember to import the module namespace:
import module namespace jn = "http://jsoniq.org/functions";

This module provides the functions defined by the JSONiq specification, sections 1.7 (Functions) and 1.10 (Update Primitives). JSONiq extends the XQuery specification to also deal with JSON data natively. See http://jsoniq.org/ for details. This module depends on having the JSONiq feature enabled in Zorba, i.e., Zorba must be compiled with ZORBA_WITH_JSON.

Author:

Markos Zaharioudakis, Matthias Brantner, Ghislain Fourny

XQuery version and encoding for this module:

xquery version "1.0" encoding "utf-8";

Zorba version for this module:

The latest version of this module is 1.0. For more information about module versioning in Zorba please check out this resource.

Module Resources
Module Dependencies

Imported modules:

Namespaces
err http://www.w3.org/2005/xqt-errors
jerr http://jsoniq.org/errors
jn http://jsoniq.org/functions
js http://jsoniq.org/types
schema http://www.zorba-xquery.com/modules/schema
ver http://www.zorba-xquery.com/options/versioning
Function Summary
External decode-from-roundtrip ( $items as item()* ) as item()*
This function decodes non-JSON types previously encoded with jn:encode-for-roundtrip.
External decode-from-roundtrip ( $items as item()*, $options as object() ) as item()*
This function decodes non-JSON types previously encoded with jn:encode-for-roundtrip.
External encode-for-roundtrip ( $items as item()* ) as item()*
This function recursively encodes non-JSON types in such a way that they can be serialized as JSON while keeping roundtrip capability.
External encode-for-roundtrip ( $items as item()*, $options as object() ) as item()*
This function recursively encodes non-JSON types in such a way that they can be serialized as JSON while keeping roundtrip capability.
External flatten ( $a as array() ) as item()*
Recursively "flatten" a JSON Array, by replacing any arrays with their members.
External is-null ( $i as xs:anyAtomicType ) as xs:boolean
Tests whether the supplied atomic item is a JSON null.
External keys ( $o as object() ) as xs:string*
Returns the names used in the object.
External member ( $a as array(), $p as xs:integer ) as item()?
Returns the member of an Array at the specified position (starting from 1).
External members ( $o as array() ) as item()*
Returns the members of an Array.
External null ( ) as js:null
Returns the JSON null.
External object ( $o as object()* ) as object()
This function allows dynamic object construction by merging all its object parameters into a single object with a so-called "simple object union".
External parse-json ( $j as xs:string? ) as json-item()*
This function parses a given string as JSON and returns a sequence of Objects or Arrays.
External parse-json ( $j as xs:string?, $o as object() ) as json-item()*
This function parses a given string as JSON and returns a sequence of Objects or Arrays.
External project ( $o as object(), $names as xs:string* ) as object()
Creates an object from the specified pairs of another given object.
External size ( $j as array() ) as xs:integer
Returns the size of a JSON Array.
External value ( $o as object(), $name as xs:string ) as item()?
Returns the value of a JSON Pair with a given name within a given JSON object.
Functions
External decode-from-roundtrip back to 'Function Summary'
declare function jn:decode-from-roundtrip (
            $items as item()*
) as item()*

This function decodes non-JSON types previously encoded with jn:encode-for-roundtrip. Calling this version of the function is equivalent to calling the 2 argument version of the function with the second argument { "prefix" : "Q{http://jsoniq.org/roundtrip}" }

Parameters:
Returns:

External decode-from-roundtrip back to 'Function Summary'
declare function jn:decode-from-roundtrip (
            $items as item()*,
            $options as object()
) as item()*

This function decodes non-JSON types previously encoded with jn:encode-for-roundtrip. The $options parameter contains options for the decoding process. Currently the only supported option is "prefix". It specifies the prefix that determines if this function decodes an item. Example: jn:decode-from-roundtrip( { "nan" : { "pre-type" : "xs:double", "pre-value" : "NaN" } }, { "prefix" : "pre-" } ) returns the same instance that would be constructed by { "nan" : xs:double("NaN") } So let $decoded := jn:decode-from-roundtrip( { "nan" : { "pre-type" : "xs:double", "pre-value" : "NaN" } }, { "prefix" : "pre-" } ) let $nan := $decoded("nan") return ($nan instance of xs:double, $nan) returns true NaN

Parameters:
Returns:
Errors:

External encode-for-roundtrip back to 'Function Summary'
declare function jn:encode-for-roundtrip (
            $items as item()*
) as item()*

This function recursively encodes non-JSON types in such a way that they can be serialized as JSON while keeping roundtrip capability. Calling this version of the function is equivalent to calling the 2 argument version of the function with the second argument { "prefix" : "Q{http://jsoniq.org/roundtrip}" "serialization-parameters" : } Note: The computations are made with respect to the static context of the caller, so that the schema type definitions are available.

Parameters:
Returns:

External encode-for-roundtrip back to 'Function Summary'
declare function jn:encode-for-roundtrip (
            $items as item()*,
            $options as object()
) as item()*

This function recursively encodes non-JSON types in such a way that they can be serialized as JSON while keeping roundtrip capability. Note: The computations are made with respect to the static context of the caller, so that the schema type definitions are available. Example: jn:encode-for-roundtrip( { "nan" : xs:double("NaN") }, { "prefix" : "pre-" } ) returns { "nan" : { "pre-type" : "xs:double", "pre-value" : "NaN" } }

Parameters:
Returns:
Errors:

External flatten back to 'Function Summary'
declare function jn:flatten (
            $a as array()
) as item()*

Recursively "flatten" a JSON Array, by replacing any arrays with their members. Equivalent to define function jn:flatten($arg as array()) { for $value in jn:values($arg) return if ($value instance of array()) then jn:flatten($value) else $value };

Parameters:
Returns:

External is-null back to 'Function Summary'
declare function jn:is-null (
            $i as xs:anyAtomicType
) as xs:boolean

Tests whether the supplied atomic item is a JSON null.

Parameters:
Returns:

External keys back to 'Function Summary'
declare function jn:keys (
            $o as object()
) as xs:string*

Returns the names used in the object. The names will be returned in an implementation-defined order

Parameters:
Returns:

External member back to 'Function Summary'
declare function jn:member (
            $a as array(),
            $p as xs:integer
) as item()?

Returns the member of an Array at the specified position (starting from 1). If the position is out of bounds of the array, returns the empty sequence.

Parameters:
Returns:

External members back to 'Function Summary'
declare function jn:members (
            $o as array()
) as item()*

Returns the members of an Array.

Parameters:
Returns:

External null back to 'Function Summary'
declare function jn:null (

) as js:null

Returns the JSON null.

Returns:

External object back to 'Function Summary'
declare function jn:object (
            $o as object()*
) as object()

This function allows dynamic object construction by merging all its object parameters into a single object with a so-called "simple object union". A simple object union creates a new object, the pairs property of which is obtained by accumulating the pairs of all operand objects. An error jerr:JNDY0003 is raised if two pairs with the same name are encountered.

Parameters:
Returns:
Errors:

External parse-json back to 'Function Summary'
declare function jn:parse-json (
            $j as xs:string?
) as json-item()*

This function parses a given string as JSON and returns a sequence of Objects or Arrays. Please note that this function allows to parse sequences of whitespace separated objects and arrays.

Parameters:
Returns:
Errors:

External parse-json back to 'Function Summary'
declare function jn:parse-json (
            $j as xs:string?,
            $o as object()
) as json-item()*

This function parses a given string as JSON and returns a sequence of Objects or Arrays.

Parameters:
Returns:
Errors:

External project back to 'Function Summary'
declare function jn:project (
            $o as object(),
            $names as xs:string*
) as object()

Creates an object from the specified pairs of another given object. Specifically, for each name in $names, if the object $o has a pair with that name, then a copy of that pair is included in the new object.

Parameters:
Returns:

External size back to 'Function Summary'
declare function jn:size (
            $j as array()
) as xs:integer

Returns the size of a JSON Array. The size of an Array is the number of members contained within it.

Parameters:
Returns:

External value back to 'Function Summary'
declare function jn:value (
            $o as object(),
            $name as xs:string
) as item()?

Returns the value of a JSON Pair with a given name within a given JSON object. If no such pair exists in the object, returns the empty sequence.

Parameters:
Returns:

blog comments powered by Disqus