Problem description: I want to use apoc.load.json
, however in a certain manner, namely instead of url or the file path use variable as argument. The reason for this is that I am sending my json as part of CURL, so I can capture it and save to variable, is there some workaround? As I need something like this (unfortunately it doesn't work, as it requires some path and not a variable):
var inputObject = req.body;
var jsonObject = JSON.stringify(inputObject);
.run('WITH $inputParam AS url CALL apoc.load.json(url) ...', {inputParam: jsonObject})
but not necessary exactly this, probably there is some other way to retrieve the json data from curl.
The curl, if it will be helpful:
curl -s -H "Content-Type: application/json" -X POST -d'{"origin":[{"label":"Alcohol drinks", "tag":[], "type":"string", "xpath":[]}, {"label":"Wine", "tag":["red","white"], "type":"string", "xpath":["Alcohol drinks"]}, {"label":"Port wine", "tag":["Portugal","sweet","strong"], "type":"string", "xpath":["Alcohol drinks","Wine"]}, {"label":"Sandeman Cask 33", "tag":["red","expensive"], "type":"string", "xpath":["Alcohol drinks","Wine","Port wine"]}], "target":[{"label":"Drinks", "tag":[], "type":"string", "xpath":[]}, {"label":"Tea", "tag":["black", "green"], "type":"string", "xpath":["Drinks"]}, {"label":"Carbonated water", "tag":[], "type":"string", "xpath":["Drinks","Tea"]}, {"label":"Pepsi", "tag":["sweet","cheap"], "type":"string", "xpath":["Drinks","Tea","Carbonated water"]}]}' http://localhost:3000/ontology
I will appreciate any help. Thank you in advance.
You don't need a apoc.load.json
function. Use an object without stringify transformation:
var inputObject = req.body;
session
.run('UNWIND $inputParam.origin AS param MERGE(label:concept {name: param.label})',
{inputParam: inputObject});
Or pass the list as a parameter:
var inputObject = req.body;
session
.run('UNWIND $inputParam AS param MERGE(label:concept {name: param.label})',
{inputParam: inputObject.origin});
P.S. You need to better understand what is objects in javascript.