Reputation: 43
this might be obvious, but not to me: I have a JSON object has a property that contains stringified JSON (don't ask why, it just has to be that way) when I UNWIND the object and grab that property (key) is there a way to convert to a map inline to the cipher query?
WITH {input} AS S
UNWIND S AS stat
WITH stat.key.str as K, stat.value as value
UNWIND K as key
RETURN key, value
returns:
key value
-----------------------------------------------------------------------------------------
{"role":"consumer","ipproto":"TCP","l7proto":"tcp:80","port":80,"dir":""} 156
{"role":"consumer","ipproto":"TCP","l7proto":"tcp:443","port":443,"dir":""} 223
{"role":"consumer","ipproto":"TCP","l7proto":"MSN","port":1863,"dir":""} 106208
is it possible to parse/load the string value in key to read it as a map or do I have to convert it outside the cypher query?
apologies - I am noob to both neo4j and cypher...
Upvotes: 4
Views: 2602
Reputation: 30397
You'll need APOC Procedures for this, specifically apoc.convert.fromJsonMap()
to convert it to a Cypher map. Here's how you would use it:
WITH {input} AS S
UNWIND S AS stat
WITH stat.key.str as K, stat.value as value
UNWIND K as key
WITH apoc.convert.fromJsonMap(key) as map, value
...
Upvotes: 6