Import Data using mg_import_csv

Hi,

[Newbie Alert]

I am learning to import a CSV file (dataset for my use-case) but my CSV is converted from a JSON file. While reading the documentation Import data | Memgraph Docs - I learned that CSV files should be classified into nodes and relationships separately.

However, I do not have it and my CSV is raw like this

I am not very sure how should I approach to populate my database here. With Neo4j, I was able to do it using apoc plugin and it sorted it out on its own using the command - CALL apoc.import.json("input.json")

Is there any similar way to do so with Memgraph?

closest hint I can find is here : https://towardsdatascience.com/how-to-implement-custom-json-utility-procedures-with-memgraph-mage-and-python-7e66bbb8b8e3

Suggestions and help are welcomed.

Thank you :slight_smile:

Update: I tried another way to import as a JSON file following this excellent article by @idespot https://towardsdatascience.com/how-to-implement-custom-json-utility-procedures-with-memgraph-mage-and-python-7e66bbb8b8e3

However, on step

Implementing the JSON Utility Query Module in Python

  1. Load JSON from a local file

Start Memgraph Lab if you haven’t done so already and run the following query:

CALL json_util.load_from_path("/usr/lib/memgraph/query_modules/data.txt") YIELD * RETURN *

I get this error in my Memgraph Lab

After googling the error, it seems something is wrong with formatting. I cross-checked with the guide and it states the same.

[{name:“Leslie”}, {name:“Ron”}, {name:“Donna”}]

Hi @red_devil!

Yes, as you have pointed out, you need at least two separate CSV files to import both nodes and relationships into Memgraph.

You can always manually split your sheet by using the data from the first column (type). One sheet would contain all the nodes and the other one all the relationships. Now you can save your sheets as CSV files and try importing them using the CSV Import Tool.

Also, thank you for pointing out the typos in the JSON data. JSON keys do need to be enclosed in quotation marks.

Good luck with your project! :slightly_smiling_face:

1 Like