Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-20-2020 10:49 PM
How do I load a JSON map in the form
{
"aaaa": {
"x": "1",
"y": "2"
},
"bbbbb": {
"x": "5",
"y": "3"
}
}
In particular, I need to get the keys "aaaa", "bbbb" ?
Thanks!
02-20-2020 11:21 PM
Hi david,
The apoc load json function supports json-paths. With a json-path query like $.*~ you should be able to fetch all top level keys from the json document.
More information on how to use the load json apoc can be found in the documentation.
https://neo4j.com/docs/labs/apoc/current/import/load-json/
Hope this helps you.
Kind regards,
Joren
02-21-2020 01:04 PM
Hi David,
My environment
You need the line into the neo4j.conf. (conf/neo4j.conf)
apoc.import.file.enabled=true
I created the data. (import/sample.json)
{
"aaaa": {
"x": "1",
"y": "2"
},
"bbbbb": {
"x": "5",
"y": "3"
}
}
This is the Cypher command.
WITH "sample.json" AS url
CALL apoc.load.json(url) YIELD value
UNWIND [k IN KEYS(value) | k] AS v
RETURN v
You can get all the keys.
v
"aaaa"
"bbbbb"
02-21-2020 02:02 PM
Thank you all.
The neo community is amazing!
02-23-2020 08:52 PM
If interested, I
retrieved key and value like so
CALL apoc.load.json("file:///license.json") YIELD value
UNWIND [k IN KEYS(value) | {key: k, value: value[k]}] AS obj
All the sessions of the conference are now available online