Product SiteDocumentation Site

8.8. libjn:remove-keys

This function iterates on the input sequence. It removes the pairs with the given keys from all objects and leaves non-objects intact.
declare function libjn:remove-keys($sequence as item()*, $keys as xs:string*) as item()*
{
  for $item in $sequence
  return typeswitch ($item)
         case $object as object() return
         {|
           for $key in $object() [ not (. = $keys) ]
           return { $key : $object($key) }
         |}
         default return $item
};
Example 8.8. Projecting objects.
Query:
libjn:remove-keys(
  (
    {
      "Captain" : "Kirk",
      "First Officer" : "Spock",
      "Engineer" : "Scott"
    },
    [ 1, 2, 3, 4 ]
    {
      "Captain" : "Archer",
      "Engineer" : "Trip",
    },
    true(),
    1,
    jn:null()
  ),
  ("Captain", "First Officer", "XQuery Evangelist")
)
Result:
{ "Engineer" : "Scott" } [ 1, 2, 3, 4 ] { "Engineer" : "Trip" } true 1 null