es:optional( $instance as map:map, $key-name as xs:string, $key-value as item()? ) as map:map
This function is deprecated and will be removed in a future release.
Add a key-value pair to a map, if the value exists, and return
the modified input map. This function is meant for use in code
generated by Entity Services.
Parameters | |
---|---|
instance | A map:map representation of an entity instance. |
key-name | A key name. |
key-value | The value to which to set the key, if the value exists. |
This function is included for use within the modules that Entity Services
generates for manipulating instance data. It is identical to
map:with
except map:with
inserts a key with a null value in the case of an empty value. This
function leaves the map unmodified if there is no value.
This function returns the original instance
, with
the key-value pair added.
xquery version "1.0-ml"; import module namespace es = "http://marklogic.com/entity-services" at "/MarkLogic/entity-services/entity-services.xqy"; json:object() =>es:optional("a", "value") =>es:optional("missing", ()) (: returns an object with one key/value pair, {"a", "value"} :)