http://jsound.io/modules/validate/map

View as XML or JSON.

Map utility

Function Summary

get ($map as object(), $key as string) as item()

Returns the value under the key.

has-key ($map as object(), $key as string) as boolean

Returns true if $key exists in the map.

set-if-empty ($map as object(), $key as xs:string, $value as item()) as boolean

Only if key doesn't exist, inserts new key and value into the map and returns true.

set ($map as object(), $key as xs:string, $value as item()) as boolean

Inserts new key and value into the map or replaces value under the exiting key.

Functions

get#2

declare  function map:get($map as object(), $key as string) as item()
Returns the value under the key.

Parameters

map as object()
the map JSON object
key as string
the key

Returns

item()
the value under the $key, () if empty Example:

has-key#2

declare  function map:has-key($map as object(), $key as string) as boolean
Returns true if $key exists in the map.

Parameters

map as object()
the map JSON object
key as string
the key

Returns

boolean
true if $key exists, false otherwise Example:

set-if-empty#3

declare  %an:sequential function map:set-if-empty($map as object(), $key as xs:string, $value as item()) as boolean
Only if key doesn't exist, inserts new key and value into the map and returns true. Otherwise returns false.

Parameters

map as object()
the map JSON object
key as xs:string
the key
value as item()
the value

Returns

boolean
true if $key is empty, false otherwise Example:

set#3

declare  %an:sequential function map:set($map as object(), $key as xs:string, $value as item()) as boolean
Inserts new key and value into the map or replaces value under the exiting key. Returns true all the time.

Parameters

map as object()
the map JSON object
key as xs:string
the key
value as item()
the value

Returns

boolean
true Example: