~zorba-coders/zorba/bug1123016

« back to all changes in this revision

Viewing changes to test/rbkt/Queries/zorba/jsoniq/descendant-objects.jq

  • Committer: Sorin Marian Nasoi
  • Date: 2013-04-09 11:44:43 UTC
  • mfrom: (11301.1.53 zorba)
  • Revision ID: spungi@gmail.com-20130409114443-89vz57gpyjzwoiok
Merged lp:zorba trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
jsoniq version "1.0";
 
2
 
 
3
declare function local:descendant-objects($i as json-item) as object*
 
4
{
 
5
 typeswitch($i)
 
6
 case object return (
 
7
     $i,
 
8
     for $k in keys($i)
 
9
     let $v := $i.$k
 
10
     where $v instance of json-item
 
11
     return local:descendant-objects($v)
 
12
   )
 
13
 case array return (
 
14
     for $v in $i()
 
15
     where $v instance of json-item
 
16
     return local:descendant-objects($v)
 
17
   )
 
18
 default return ()
 
19
};
 
20
 
 
21
let $o := (
 
22
  { "foo" : 42, "bar" : { "blub" : 23 } },
 
23
  { "foo" : 42, "bar" : { "42" : 23 } })
 
24
return
 
25
distinct-values($o ! local:descendant-objects($$) ! $$())