Import csv file (dictionary format?)

Hi, I use neo4j browser and i have a Q.
Can I import a csv file like this format? (no column data on top)

LOAD CSV FROM '{csv-dir}/neo4j-sample-data.csv' AS info FIELDTERMINATOR ','
CREATE (:Info { name: info[1].name, count:info[1].count. asset_id:info[1].asset_id})

I want get Datas { name, count, asset_id} .
Is it possible?Thank you.

Please check cypher query syntax for exact details on cypher syntax reference card.

Thanks for reply and I did it.
read syntax reference. but, failed :frowning_face:

It is so difficult to me
oh my.....

Please read the error carefully. After careful consideration it looks like problem is with
name: info[1].name column it is expecting a map data structure but you are supplying a string instead of Map. So please look for conversion functions from string to map on ref card that I earlier pointed to.
I hope that this will fix the issue at your end.

It seems you have a json object as the value in CSV. This is not how load csv works. It converts a single row into map.

For ex:

if you have data

id, name

the resulting map would be

   id: 1,
   name: "test"

In your case the map seen by db would be

    n: "{name:CVE-2014-3539,count:1,asset_id:26...}"

All the values if the type cannot be inferred are treated as strings.

So "info.n" will give you access to the string. But you need convert that string to map. Even with apoc it might not be possible because this is not a valid json, as the strings and names are enclosed in quotes.

If you want this data in CSV format then it should be like this


What you might want to try, is import as CSV, then take the string (which you want to become a JSON), and apply a String -> JSON function.


Hi @Novice ,

this is my code, please give a try



Cypher Query

CALL apoc.load.csv('demo.csv' ,{skip:1,header:FALSE} )
YIELD   list
with  apoc.convert.toString(list) as base
WITH ['\{', '\}','\[','\]',  'name:','count:','asset_id:','privilege:','seq:', '\"'] as to_remove, base
with base, reduce(vari=base, word in to_remove | apoc.text.replace(vari,word,'')) as filtered 
with  apoc.convert.toStringList(split(filtered,",")) as tt
create (a:Item) set = trim(tt[0]), a.count=toInteger(trim(tt[1])),a.asset_id=toInteger(trim(tt[2])),a.privilege=trim(tt[3]),a.seq=toInteger(trim(tt[4]))

Result -

match(n) return(n)
│"n"                                                                   │
│{"name":"CVE-2014","count":1,"privilege":"0","asset_id":1111,"seq":1} │

Note -

  1. above script has CREATE not MERGE. So, be careful with incremental inserts. make sure the csv files doesn't have duplicates. (you can create constraint, but didn't try it).
  2. I didn't know about the data, so have few data converted to int.
  3. i doubt your csv file. was it originally a json file and then you removed "," at the end ? I am not sure.

give it a try and let me know how it goes.