Search code examples
memgraphdb

How can I import data into Memgraph from local JSON file?


I have data that I want to import into the database in JSON format. I want to import parts of that data as graph objects: nodes or relationships. My JSON file looks like this:

{
  "first_name": "Jessica",
  "last_name": "Rabbit",
  "pets": ["dog", "cat", "bird"]
}

How can I do that?


Solution

  • To create a node with the label Person and first_name, last_name and pets as properties, run the following Cypher query:

    CALL json_util.load_from_path("path/to/data.json")
    YIELD objects
    UNWIND objects AS o
    CREATE (:Person {first_name: o.first_name, last_name: o.last_name, pets: o.pets});