cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Computed Property Names in Neo4j?

klug
Node Link

Hello everyone,
for a cypher statement that I am coding I would love to know whether there is a cypher functionality like in javascript's [ key ] : value.
I am querying an object which is build as followed:

{
          "Id": "Floor",
          "IdType": "string",
          "Value": "",
          "Unit": "none",
}

And I would like to have a result which is built with the node's property "Id" as key and the node's property "Value" as value:

{
    //Id : Value
    "Floor":  "XYZ"
}
1 ACCEPTED SOLUTION

filantrop
Node Clone

Hi klug,
I hope this snippet of query can help you:

with obj.Id as keyName

match (n)
where n[keyName] is not null
with n,keyName,n[keyName] as value
with apoc.map.fromPairs([[keyName,value]]) as ns
return ns


View solution in original post

2 REPLIES 2

filantrop
Node Clone

Hi klug,
I hope this snippet of query can help you:

with obj.Id as keyName

match (n)
where n[keyName] is not null
with n,keyName,n[keyName] as value
with apoc.map.fromPairs([[keyName,value]]) as ns
return ns


Thanks @filantrop! The apoc function fromPairs is the perfect fit for my problem.
Thanks for the fast and useful answer