How to filter the map based on the "values" of the map?

Hi professionals,

When I am writing Cypher, I encountered such a complicated data structure:

What I want is to get 58.0 when I ask for "enrollmentMale", and get 42.0 when I ask for "enrollmentFemale".

Normally, the key-value pair should be {"enrollmentMale": 58.0, "enrollmentFemale": 42.0}. However, the json file makes it a problem for me by putting both the key and the value in the map "values". How could I get the value for enrollmentMale/enrollmentFemale?

I tried to unwind the list, and for each node, I could get two maps. How could I determine the value based on the other value in the map?

Thank you so much for your help!

Here is cypher solution:

with [{key:"enrollmentMale", value:58.0},{key:"enrollmentFemale", value: 42.0}] as map
return [i in map where i.key = "enrollmentMale" | i.value] as male_value, 
[i in map where i.key = "enrollmentFemale" | i.value] as female_value

Screen Shot 2023-07-10 at 3.58.12 PM

1 Like

This is brilliant...Thank you so much!

1 Like