Hi Danny,
You could put the FLWOR statement *inside* the array-node constructor:
array-node{
for $type in $values
…
}
Or consider using server-side JavaScript..
Cheers,
Geert
From: Danny Sinang <[email protected]<mailto:[email protected]>>
Reply-To: MarkLogic Developer Discussion
<[email protected]<mailto:[email protected]>>
Date: Friday, April 17, 2015 at 2:36 PM
To: general
<[email protected]<mailto:[email protected]>>
Subject: [MarkLogic Dev General] Adding JSON array members in ML8
I've read about ML8's JSON constructors so I started rewriting my ML7 XQuery
for better readabilty.
Below is my ML8 code (which I haven't tested yet) which has a for loop that
adds members to a JSON array.
My question is, is there another way (more akin to constructors) of adding
members to a JSON array other than calling json:array-push ?
Regards,
Danny
let $main-array := array-node { }
let $_ :=
for $typein $values
let $type-name := helper:get-type-name($chart-name, $type)
return
json:array-push ($main-array, object-node { "name" :
$type-name,
"children" :
array-node {
object-node { "name" : $type-name,
"id" : helper:get-clean-id ($type),
"size" : cts:frequency($type)
}
}
}
)
let $main-object := object-node { "name" : "flare", "children" :
$main-array }
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general