items of type map(*) cannot be serialized

Wednesday, 10 November 2021 · 3 messages
MH
Martin Honnenin reply to Jonathan Robie, 10 Nov 2021, 20:3410 Nov 2021 19:41 #
Quoted text · Jonathan Robie · 33 lines
On 10.11.2021 19:34, Jonathan Robie wrote: > I want to serialize JSON. Consider the following function: > > declare function local:index() > { > array{ $levinsohn/levinsohn/feature/header ! map {./name : > ./description ! string() } } > }; > > When I run that, I get output that looks like this: > > [map { > "Ambiguous": "Marked but ambiguous constituent order." > }, map { > "annotations": "Inline annotations." > } > !!! SNIP !!!] > > That won't work as output in a REST API, so I want to serialize that > without the map keyword. I tried to use fn:serialize(): > > declare function local:index() > { > array{ $levinsohn/levinsohn/feature/header ! map {./name : > ./description ! string() } } ! serialize(.) > }; > > That gave me this error: > > items of type map(*) cannot be serialized > > > So ... what's the right way to do this?
I would use
   serialize(local:index(), map { 'method' : 'json' })
to serialize the whole array as JSON
JR
Jonathan Robie10 Nov 2021 20:34 #
I want to serialize JSON. Consider the following function:
declare function local:index()
{
 array{ $levinsohn/levinsohn/feature/header ! map {./name : ./description !
string() } }
};
When I run that, I get output that looks like this:
[map {
  "Ambiguous": "Marked but ambiguous constituent order."
}, map {
  "annotations": "Inline annotations."
}
!!! SNIP !!!]
That won't work as output in a REST API, so I want to serialize that without the map keyword. I tried to use fn:serialize():
declare function local:index()
{
 array{ $levinsohn/levinsohn/feature/header ! map {./name : ./description !
string() } } ! serialize(.)
};
That gave me this error: items of type map(*) cannot be serialized So ... what's the right way to do this? Jonathan
JR
Jonathan Robiein reply to Martin Honnen, 10 Nov 2021, 19:4110 Nov 2021 20:49 #
Perfect - thanks! Jonathan
Quoted text · Jonathan Robie · 42 lines
On Wed, Nov 10, 2021 at 1:41 PM Martin Honnen <martin.honnen at gmx.de> wrote: > On 10.11.2021 19:34, Jonathan Robie wrote: > > I want to serialize JSON. Consider the following function: > > > > declare function local:index() > > { > > array{ $levinsohn/levinsohn/feature/header ! map {./name : > > ./description ! string() } } > > }; > > > > When I run that, I get output that looks like this: > > > > [map { > > "Ambiguous": "Marked but ambiguous constituent order." > > }, map { > > "annotations": "Inline annotations." > > } > > !!! SNIP !!!] > > > > That won't work as output in a REST API, so I want to serialize that > > without the map keyword. I tried to use fn:serialize(): > > > > declare function local:index() > > { > > array{ $levinsohn/levinsohn/feature/header ! map {./name : > > ./description ! string() } } ! serialize(.) > > }; > > > > That gave me this error: > > > > items of type map(*) cannot be serialized > > > > > > So ... what's the right way to do this? > > I would use > > serialize(local:index(), map { 'method' : 'json' }) > > to serialize the whole array as JSON > >

⚡Generated with XQuery