Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-08-2021 04:56 PM
I would like to pass an external variable to:
call apoc.load.json("file:///...")
I tried the command below (with the appropriate query run in python) but it didn't worked with an error of not finding the file.
call apoc.load.json("file:///$filename")
So how i'm going to pass the external variable to this path ?
Solved! Go to Solution.
02-09-2021 10:35 AM
If you are running it through driver from java or python. Try form the query with string concatenation and pass it.
x = {'filename': 'filename.json'}
q="call apoc.load.json('file:///"+x['filename']+"')"
this is in python, check with quotes accordingly.This is the not the way you want but this will do the work or as @dana.canzano said
q = """call apoc.load.json($filepath)"""
x= {'filepath': 'file:///filename.json'}
session.run(q,x)
02-08-2021 05:17 PM
perhaps 2 options and tested with Neo4j 4.2.3 and cypher-shell but
@neo4j> :param f=>'file:///example.json'
@neo4j> :params
:param f => 'file:///example.json'
@neo4j> call apoc.load.json($f) yield value;
which defines parameter f
to have the value file:///example.json'
or
with 'file:///example.json' as f call apoc.load.json(f) yield value return value;
02-09-2021 03:52 AM
I did know these options though i can't find the connection on how i would pass the last part of the path (the file.json) as an external variable. For example how i'm gonna do this:
q = """call apoc.load.json('file:///$filename')"""
x= {"filename": filename}
session.run(q,x)
Because, that way doesn't work (and it's logical because inside the path cypher can't recognize the symbol $)
02-09-2021 10:35 AM
If you are running it through driver from java or python. Try form the query with string concatenation and pass it.
x = {'filename': 'filename.json'}
q="call apoc.load.json('file:///"+x['filename']+"')"
this is in python, check with quotes accordingly.This is the not the way you want but this will do the work or as @dana.canzano said
q = """call apoc.load.json($filepath)"""
x= {'filepath': 'file:///filename.json'}
session.run(q,x)
All the sessions of the conference are now available online