Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
02-25-2020 01:54 AM
Hello there,
I'm trying to get a list of strings without null values, but I can't get the result that I want.
I've tried it in two different ways:
WITH 'recursivo.json' AS json_file
CALL apoc.load.json(json_file, "$..id_requisito") YIELD value AS result
with json_file, result.result AS keys
return keys
This was the first one and the result I got was this:
The other way is this:
WITH 'recursivo.json' AS json_file
CALL apoc.load.json(json_file) YIELD value AS result
with json_file, result.id_requisito AS keys
return keys
And the result:
If you want to know what's the JSON file:
[
{
"id_requisito" : "R1",
"sentence" : {
"operator": "&&",
"left" : "H",
"right" : {
"operator" : "&&",
"left" : "A",
"right" : {
"operator" : "||",
"left" : "B",
"right" : "C"
}
}
}
},
{
"id_requisito" : "R2",
"sentence" : {
"operator": "||",
"left" : "A",
"right" : "B"
}
},
{
"id_requisito" : "R3",
"sentence" : {
"operator": "&&",
"left" : {
"operator" : "||",
"left" : "A",
"right" : "B"
},
"right" : "C"
}
}
]
It would be possible to remove the null values or create a list of strings?
Thank you.
Solved! Go to Solution.
02-25-2020 05:55 AM
You can try this code
WITH 'recursivo.json' AS json_file
CALL apoc.load.json(json_file, "$..id_requisito") YIELD value AS result
WITH json_file, [x in result.result WHERE x is not null | x] as AS keys
return keys
02-25-2020 02:15 AM
You should be able to do something like:
WITH 'recursivo.json' AS json_file
CALL apoc.load.json(json_file, "$..id_requisito") YIELD value AS result
with json_file, result.result AS keys
WHERE keys is not null
return keys
or maybe:
CALL apoc.load.json(json_file, "$..id_requisito") YIELD value AS result
with json_file, result.result AS keys
unwind keys as k
where k is not null
return keys
Depending on how you want the output and how it works out.
02-25-2020 02:30 AM
Hi Michael,
I've tried both of them and the first one has this result:
The second one returns an error:
Thank you for your answer.
02-25-2020 02:56 AM
It sounds like it would be beneficial if you could pre-process the data to remove nulls. I'm not sure if you're getting this from an API or some other source but cleaning your data is always the largest part of the battle.
02-25-2020 05:55 AM
You can try this code
WITH 'recursivo.json' AS json_file
CALL apoc.load.json(json_file, "$..id_requisito") YIELD value AS result
WITH json_file, [x in result.result WHERE x is not null | x] as AS keys
return keys
02-26-2020 01:01 AM
You got it, thank you
All the sessions of the conference are now available online