Product SiteDocumentation Site

8.2. libjn:descendant-arrays

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