JSON update primitives
A Pending Update List is an unordered list of update primitives. Update primitives are internal and do not appear in the syntax. Each kind of update primitive models one individual update to an object or an array.
A Pending Update List can by analogy be seen as the diff between two git revisions, and a single update primitive can be seen, with this same analogy, as the difference between two single lines of code. Thus, the JSONiq Update Facility is to trees what git is to lines of text: a "tree diff" language.
JSONiq adds the following new update primitives, specific to JSON. They are similar to those defined by the XQuery Update Facility for XML.
Update primitives within a PUL are applied with strict snapshot semantics. For examples, the positions are resolved against the array before the updates. Names are resolved on the object before the updates.
Update primitive for objects and arrays (in collections or in memory)
jupd:insert-into-object(
$target as object(),
$content as object())
Inserts all pairs of the object $content into the object $target.
jupd:insert-into-array(
$target as array(),
$position as xs:integer,
$content as item()*)
Inserts all items in the sequence $content before position $position into the array $target.
jupd:delete-from-object(
$target as object(),
$keys as xs:string*)
Removes the pairs the names of which appear in $keys from the object $target.
jupd:delete-from-array(
$target as array(),
$position as xs:integer)
Removes the item at position $position from the array $target (causes all following items in the array to move one position to the left).
jupd:replace-in-array(
$target as array(),
$position as xs:integer,
$content as item())
Replaces the item at position $position in the array $target with the item $content (do nothing if $position is not comprised between 1 and jdm:size($target)).
jupd:replace-in-object(
$target as object(),
$key as xs:string,
$content as item())
Replaces the value of the pair named $key in the object $target with the item $content (do nothing if there is no such pair).
jupd:rename-in-object(
$target as object(),
$key as xs:string,
$content as xs:string)
Renames the pair originally named $key in the object $target as $content (do nothing if there is no such pair).
Update primitives at the collection level
Credits: Dwij Dixit/Ghislain Fourny (student project at ETH)
jupd:create-collection(
$name as string,
$mode as string,
$content as item()*)
Creates a collection initialized with the provided items. Mode determines the kind of collection (e.g., a Hive metastore table, a delta lake file, etc).
jupd:truncate-collection(
$name as string,
$mode as string)
Deletes the specified collection.
jupd:edit(
$target as item(),
$content as item())
Modifies an item in a collection into another item, preserving its identity and location.
jupd:delete-in-collection(
$target as item())
Deletes the provided item from its collection.
jupd:insert-first-into-collection(
$name as string,
$mode as string,
$content as item()*)
Inserts the provided items at the very beginning of the specified collection.
jupd:insert-last-into-collection(
$name as string,
$mode as string,
$content as item()*)
Inserts the provided items at the very end of the specified collection.
jupd:insert-before-into-collection(
$target as item,
$content as item()*)
Inserts the provided items before the specified item in its collection.
jupd:insert-last-into-collection(
$target as item,
$content as item()*)
Inserts the provided items after the specified item in its collection.
Last updated