Import CSV to Neo4j

5 min read
Step-by-step guide to importing CSV files to Neo4j using modern tools and APIs.

How to Import CSV Data into Neo4j (Without the Headaches)

Importing structured data from CSV files into Neo4j is a common need for developers building graph-powered applications—whether you’re managing user profiles, product relationships, or social connections. But working directly with flat spreadsheets introduces several challenges: invalid data, duplicate records, and inconsistent formats.

This guide explains how to import CSVs into Neo4j, avoid common pitfalls, and integrate a developer-friendly tool—CSVBox—to streamline the process for modern SaaS products and web apps.


Who Should Read This

This article is for:

  • Developers and data engineers working with Neo4j
  • SaaS teams importing user-uploaded CSVs
  • Founders or technical leaders building analytics, CRM, or recommendation tools
  • Anyone facing messiness in turning spreadsheet data into structured graph records

Why Import CSV Into Neo4j?

Neo4j is a leading graph database built to model and query connected data using nodes and relationships. Use cases include:

  • Social graphs (friends, followers, influencers)
  • Product recommendation networks
  • Fraud detection systems
  • Knowledge graphs and entity models

However, raw tabular data—especially from spreadsheets or exports—isn’t graph-ready. You first need to import it.


Common Methods to Import CSV into Neo4j

Neo4j offers several ways to load CSV data:

  • ✅ Cypher’s built-in LOAD CSV command
  • ✅ Neo4j Data Importer UI (great for beginners)
  • ✅ Backend integration via code (suitable for apps)

For production use (or SaaS platforms where users upload CSVs), backend automation is key.

Below, we cover the step-by-step process using Cypher’s LOAD CSV.


Step-by-Step: Import CSV to Neo4j Using Cypher

1. Prepare your CSV file

Ensure your file is:

  • UTF-8 encoded
  • Well-structured with clear headers
  • Free of empty rows or mismatched columns

Example format: users.csv

userId,fullName,email
101,Alice Johnson,[email protected]
102,Bob Smith,[email protected]

Place the file in Neo4j’s /import folder, or serve it via HTTPS for cloud environments like Neo4j Aura.

2. Launch the Neo4j Browser

If using local Neo4j, open your browser at:

http://localhost:7474

Login and access the Cypher editor.

3. Import Data with Cypher’s LOAD CSV

Use the following query to create User nodes from the CSV:

LOAD CSV WITH HEADERS FROM 'file:///users.csv' AS row
CREATE (:User {
  id: toInteger(row.userId),
  name: row.fullName,
  email: row.email
});

Ensure the file path uses file:/// and resides in the import directory.

4. Create Relationships from Additional CSVs

Suppose you have a friendships.csv file:

sourceId,targetId
101,102

To represent those as graph relationships:

LOAD CSV WITH HEADERS FROM 'file:///friendships.csv' AS row
MATCH (a:User {id: toInteger(row.sourceId)})
MATCH (b:User {id: toInteger(row.targetId)})
CREATE (a)-[:FRIENDS_WITH]->(b);

With that, you’ve transformed tabular data into a connected graph.


Common Issues with CSV Imports in Neo4j

Real-world CSVs often present messy, edge-case scenarios. Here’s how to handle the most frequent ones.

1. File Not Found or Access Denied

Likely causes:

  • You’re referencing a local file not in the /import directory
  • You’re using Neo4j Cloud, which blocks local file access

✅ Solution: For Neo4j Aura or Sandbox, use a secure HTTPS URL:

LOAD CSV FROM 'https://example.com/data.csv' AS row

2. Wrong Data Types

Neo4j reads everything as strings by default.

✅ Solution: Use type conversion functions:

toInteger(row.userId)
toFloat(row.price)
datetime(row.createdAt)

3. Duplicate Nodes from Multiple Imports

Using CREATE blindly creates new nodes—even duplicates.

✅ Solution: Use MERGE to avoid duplicates:

MERGE (u:User {id: toInteger(row.userId)})
SET u.name = row.fullName, u.email = row.email;

4. Dirty or Misformatted User Files

Real user-uploaded CSVs can contain:

  • Empty lines
  • Inconsistent headers
  • Misspelled columns (e.g. “full name” vs “fullname”)

✅ Solution: Validate and normalize CSVs before importing. See: CSVBox (below).


Using CSVBox to Streamline CSV Imports into Neo4j

CSVBox is a developer-first tool that simplifies importing user-uploaded spreadsheets. It helps you:

  • Validate headers and formats
  • Ensure data types match
  • Forward clean data to your backend for processing

Instead of writing custom file parsers, you can embed a CSV uploader in your app with just a few lines of code.

Key Features of CSVBox

  • 🔍 Field-level validation (types, required, regex, enums)
  • 🚀 Clean JSON export via webhook or API
  • 👤 End-user friendly upload UI
  • 🌐 Works with any backend (Node.js, Python, Go, Java, etc.)

Example: How CSVBox Works with Neo4j

1. Embed the Uploader in Your App

<script src="https://js.csvbox.io/entry.js"></script>
<button 
  class="csvbox-launch"
  data-upload-id="YOUR_UPLOAD_ID"
>
  Upload CSV
</button>

2. Define Validation Rules in CSVBox Dashboard

Specify column names, data types, and required fields.

3. Handle Webhook in Your Backend

Example (Node.js + Neo4j):

app.post('/csvbox/webhook', async (req, res) => {
  const dataRows = req.body.data; // array of validated rows

  for (const row of dataRows) {
    await session.run(`
      MERGE (u:User {id: $id})
      SET u.name = $name, u.email = $email
    `, {
      id: parseInt(row.userId),
      name: row.fullName,
      email: row.email
    });
  }

  res.status(200).send('Data imported to Neo4j');
});

✅ No need to expose file parsing endpoints or sanitize CSVs manually.

🔗 See the full CSVBox docs: Getting Started


FAQs About CSV Imports in Neo4j

How can I avoid creating duplicate nodes?

Use MERGE in your Cypher query instead of CREATE. MERGE creates the node only if one doesn’t already exist based on the specified pattern.

Can I import CSVs into Neo4j hosted on the cloud (e.g., Aura)?

Yes! Use a CSV URL that’s publicly accessible via HTTPS:

LOAD CSV FROM 'https://yourdomain.com/data.csv' AS row

Aura doesn’t support loading from local file paths.

Can CSVBox send data directly into Neo4j?

Not directly. CSVBox sends cleaned data to your backend (via webhook or API), and your server then interacts with Neo4j using official drivers or Cypher.

What happens to invalid rows with CSVBox?

CSVBox validates rows in the browser. Invalid entries are flagged with helpful error messages—before they hit your server.

What tech stacks work with CSVBox?

CSVBox works with any backend framework: Node, Django, Rails, Go, .NET, or even serverless APIs. You receive clean JSON payloads ready to insert into Neo4j.


Final Thoughts

Importing CSVs into Neo4j can be powerful—but painful—if the data isn’t clean or structured properly. For one-off scripts, Cypher’s LOAD CSV is great.

But if you’re building a data-driven SaaS or need to accept user-uploaded spreadsheets at scale, you should layer in a CSV import solution with validation, API support, and end-user-friendly feedback.

That’s where CSVBox shines.

Try it out: https://csvbox.io


Looking to streamline CSV onboarding into Neo4j? Embed a CSV uploader in minutes and start ingesting clean, validated data directly into your graph app.

Canonical URL: https://csvbox.io/blog/import-csv-to-neo4j

Related Posts