Groovy script execution results in wrapping JSON in an array

139 views
Skip to first unread message

Ray Scott

unread,
Nov 2, 2017, 1:46:16 PM11/2/17
to Gremlin-users
Hi,

Attempting to generate JSON from a Groovy script submitted to GS. My hold on Groovy is almost non-existent. However, what is happening doesn't seem to add up.

def map = [:]
map
.put('name', 'rayscott')
map
.put('hip', false)
builder
= new groovy.json.JsonBuilder(map)
builder
.toString()


If I submit this script, the data that is returned is wrapped as an array...

{"requestId":"352939bd-7a5c-4f1b-828d-ea667dc96570","status":{"message":"","code":200,"attributes":{}},"result":{"data":["{\"name\":\"rayscott\",\"hip\":false}"],"meta":{}}}

data = 
["{\"name\":\"rayscott\",\"hip\":false}"]

I have to pull the JSON out of the array to get what I really want...

{"name":"rayscott","hip":false}


Does anyone know why this happens, and/or how to stop its from happening? 

My end goal here is to return JSON formatted data back from the server. I've tried JsonOutput, JsonBuilder.getContent, but what is generated is unusable.

Thanks.

Stephen Mallette

unread,
Nov 2, 2017, 1:50:48 PM11/2/17
to Gremlin-users
Gremlin Server converts all results to iterators so even a returned String becomes a SingleIterator with one item in it.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/5bab8ce4-c5cd-4fee-b7c9-91bb2f800592%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ray Scott

unread,
Nov 2, 2017, 1:55:11 PM11/2/17
to Gremlin-users
I will put a big sign on the wall. I should have asked this question 2 hours ago :) 

So that's why it doesn't appear to cause a problem if your code results in an array being produced. It doesn't wrap the array in an array. Oh well, at least I know.
 

On Thursday, 2 November 2017 17:50:48 UTC, Stephen Mallette wrote:
Gremlin Server converts all results to iterators so even a returned String becomes a SingleIterator with one item in it.
On Thu, Nov 2, 2017 at 1:46 PM, 'Ray Scott' via Gremlin-users <gremli...@googlegroups.com> wrote:
Hi,

Attempting to generate JSON from a Groovy script submitted to GS. My hold on Groovy is almost non-existent. However, what is happening doesn't seem to add up.

def map = [:]
map
.put('name', 'rayscott')
map
.put('hip', false)
builder
= new groovy.json.JsonBuilder(map)
builder
.toString()


If I submit this script, the data that is returned is wrapped as an array...

{"requestId":"352939bd-7a5c-4f1b-828d-ea667dc96570","status":{"message":"","code":200,"attributes":{}},"result":{"data":["{\"name\":\"rayscott\",\"hip\":false}"],"meta":{}}}

data = 
["{\"name\":\"rayscott\",\"hip\":false}"]

I have to pull the JSON out of the array to get what I really want...

{"name":"rayscott","hip":false}


Does anyone know why this happens, and/or how to stop its from happening? 

My end goal here is to return JSON formatted data back from the server. I've tried JsonOutput, JsonBuilder.getContent, but what is generated is unusable.

Thanks.

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages