Return JSON from Cypher

1,742 views
Skip to first unread message

Johnny Luu

unread,
Jun 22, 2012, 10:47:13 PM6/22/12
to ne...@googlegroups.com
At the moment Cypher always returns Array data.

I think there is many use cases where you want to return JSON data instead directly from Cypher.

Eg.

START user = node({id})
RETURN {id: ID(user), name: user.name, age: user.age}

Gives a HTTP body:

{"id": 101, "name": "Neo", age: "33"}

In this way we don't have to convert the Array data into JSON manually in our application server.

And if it's multiple nodes returned:

START users = node:users("name: *")
RETURN {id: ID(user), name: user.name, age: user.age}

We get:

[
  {"id": 101, "name": "Neo", age: "33"}
  {"id": 101, "name": "Trinity", age: "30"}
  {"id": 101, "name": "Morpheus", age: "40"}
]

I feel returning JSON as well could be a natural thing.

Johnny

Michael Hunger

unread,
Jun 23, 2012, 5:10:57 AM6/23/12
to ne...@googlegroups.com
As this is a representation thing it doesn't belong into the query.

I'd rather have a different representation selected by Http header or http query parameter.

Nigel Small

unread,
Jun 23, 2012, 5:16:06 AM6/23/12
to ne...@googlegroups.com
My command line cypher tool can return JSON. Install py2neo with:

pip install py2neo

And you can then run something like:

cypher -f json "start z=node(1) return z"

from the command line. Think I ought to document this more somewhere!

Nige

Michael Hunger

unread,
Jun 23, 2012, 5:57:49 AM6/23/12
to ne...@googlegroups.com
Right but that also happens on the application side.

OTOH transferring the array requires much less space over the wire and converting the result on the fly into a map (as needed) shouldn't make that much of a problem.

Michael
Reply all
Reply to author
Forward
0 new messages