my python script is
import json
from neo4j import GraphDatabase
uri = "bolt://localhost:7687"
user = "neo4j"
password = "Praveen@1432"
with open(r"C:\Users\veluguri.kumar\Downloads\Interfaces.json") as f:
json_data = json.load(f)
driver = GraphDatabase.driver(uri, auth= (user, password))
def create_node(json_obj):
node_label = "Interface"
props = ", ".join([f"{key}: '{value}'" for key, value in json_obj.items()])
#print(f"JSON data : {json_obj}")
query = f"""
MERGE (n:{node_label} {{ interface_name: "{json_obj["interface_name"]}"}})
ON CREATE SET n.{props}
ON MATCH SET n.{props}
"""
return query
with driver.session() as session:
for item in json_data:
query = create_node(item)
result = session.run(query, item)
driver.close()
my error is
= RESTART: D:/veluguri.kumar/OneDrive - Infosys Limited/Desktop/python_codes/interface.py
Traceback (most recent call last):
File "D:/veluguri.kumar/OneDrive - Infosys Limited/Desktop/python_codes/interface.py", line 32, in <module>
result = session.run(query, item)
File "C:\Users\veluguri.kumar\AppData\Roaming\Python\Python311\site-packages\neo4j\_sync\work\session.py", line 313, in run
self._auto_result._run(
File "C:\Users\veluguri.kumar\AppData\Roaming\Python\Python311\site-packages\neo4j\_sync\work\result.py", line 181, in _run
self._attach()
File "C:\Users\veluguri.kumar\AppData\Roaming\Python\Python311\site-packages\neo4j\_sync\work\result.py", line 301, in _attach
self._connection.fetch_message()
File "C:\Users\veluguri.kumar\AppData\Roaming\Python\Python311\site-packages\neo4j\_sync\io\_common.py", line 178, in inner
func(*args, **kwargs)
File "C:\Users\veluguri.kumar\AppData\Roaming\Python\Python311\site-packages\neo4j\_sync\io\_bolt.py", line 849, in fetch_message
res = self._process_message(tag, fields)
File "C:\Users\veluguri.kumar\AppData\Roaming\Python\Python311\site-packages\neo4j\_sync\io\_bolt5.py", line 369, in _process_message
response.on_failure(summary_metadata or {})
File "C:\Users\veluguri.kumar\AppData\Roaming\Python\Python311\site-packages\neo4j\_sync\io\_common.py", line 245, in on_failure
raise Neo4jError.hydrate(**metadata)
neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input ':': expected "." or "=" (line 3, column 39 (offset: 91))
" ON CREATE SET n.interface_name: 'Cable0/0/0', network_interface_id: 'Cable0/0/0', interface_type: 'logical', device_id: 'JNP10008720', description: 'None', oper_status: 'None', parent: '[]'"
^}