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.

Apoc load json "map"

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!

4 REPLIES 4

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

Hi David,

My environment

  • Neo4j 3.5.14
  • APOC (plugins/apoc-3.5.0.9.jar)

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"

Thank you all.
The neo community is amazing!

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