descendant-pairs

This function returns all descendant pairs within the supplied items.

declare function descendant-pairs($seq as item*)
{
  for $i in $seq
  return typeswitch ($i)
  case object return
    for $k in keys($o)
    let $v := $o.$k
    return ({ $k : $v }, descendant-pairs($v))
  case array return descendant-pairs($i[])
  default return ()
};
      

Example 179. Accessing all descendant pairs

let $o := 
{
  "first" : 1,
  "second" : { 
    "first" : "a", 
    "second" : "b" 
  }
}
return descendant-pairs($o)
        

Result (run with Zorba): An error was raised: "descendant-pairs": function with arity 1 not declared