Importing json list into neo4j using python

Hi Everyone,

I am facing some issues while working with JSON list . Please find my piece of code for reference.

list_json = [{json1}, {json2}.......]

query_q = ''' WITH ''' + list_json + ''' as value
                  UNWIND value as node 
                  MATCH (e:t{txid: node.id}) SET e.tx_h = node.h  '''

session.run(query_q )

Here i am not able to concat list with query
could anyone tell me what i am doing wrong and how can i do that

You need to pass list_json as a parameter to your query, and not interpolate it into the string.

What you're trying to do is turn list_json into a big chunk of string cypher, which won't work. What you instead need to do is refer in the cypher query string to a parameter called list_json, and then pass it as an argument to session.run, so that the driver will do all of the interpolation for you.

Here's an example of appropriate parameter usage:

https://neo4j.com/docs/api/python-driver/current/#quick-example

Hi David,

Thanks for your reply. i will try this way as well.
but for the time being i want some help as well from you .
is there any limitation in neo4j regarding session creation ?
I am asking this thing because of below scenario:

i have around 10k jsons and i need to ingest these json data in neo4j. I am doing this with python.
i created a function which will fetch json one by one from source and pass this json in cypher
WITH apoc.convert.fromJsonMap(''' + data_json + ''') as value UNWIND value.tx as node MATCH (e:transaction{txid: node.txid}) # SET e.tx_hex = node.hex

now it is working fine for some 100 jsons but after 500 json file it is running the script but not inserting any data and not getting any error as well

could you please help me into this ?

This is the same situation in a slightly different form. Don't interpolate the text of data_json into a string and then ask APOC to parse it. Instead, send the JSON as a parameter into the cypher query.

Hi @david.allen ,

Thanks for your help . it seems working fine with parameter but could you please tell me how to speedup the process . currently it is taking 10 sec for 6 Mb json file with below query

WITH apoc.convert.fromJsonMap($param) as value
 UNWIND value.tx as node 
MATCH (e:transaction{txid: node.txid})  SET e.tx_hex = node.hex

please open a separate topic. Use the EXPLAIN feature to show what the query is doing -- and also please follow up with what else you've tried