Product SiteDocumentation Site

8.3. libjn:descendant-objects

This function returns all objects contained within the supplied items, regardless of depth.
declare function libjn:descendant-objects($sequence as item()*) as object()*
{
  for $item in $sequence
  return typeswitch ($item)
  case object() return (
    $item,
    libjn:descendant-objects(libjn:values($item))
  )
  case array() return
    libjn:descendant-objects($item())
  default return ()
};
Example 8.2. Accessing all descendant objects
Query:
libjn:descendant-objects(
  (
    { "foo" : { "bar" : [ 1, 2 ] } },
    [ [ { "foo" : "bar", "bar" : "foo" } ] ],
    true(),
    1,
    jn:null()
  )
)
Result:
{ "foo" : { "bar" : [ 1, 2 ] } }
{ "bar" : [ 1, 2 ] }
{ "foo" : "bar", "bar" : "foo" }