Search code examples
memgraphdb

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


I know how to import data from the local JSON file, but can the same thing be done for the file that is stored in a remote location? My JSON file is located on a remote server, and it can be accessed via HTTPS protocol.

Here is what the file data.json looks like:

{
  "first_name": "James",
  "last_name": "Bond",
  "pets": ["dog", "cat", "fish"]
}

Solution

  • To load JSON files from another local or remote location, just replace the argument of the procedure with the appropriate path or URL. If you want to create a different kind of graph, you need to change the query accordingly.

    To create a node with the label Person and first_name, last_name and pets as properties from the data.json file. You can run the following query:

    CALL json_util.load_from_url("https://download.memgraph.com/asset/mage/data.json")
    YIELD objects
    UNWIND objects AS o
    CREATE (:Person {first_name: o.first_name, last_name: o.last_name, pets: o.pets});