Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
12-09-2021 08:43 AM
I have a json file that I'm trying to import and build a graph.
The code is:
Cypher statement: //Load_JSON_Country
CALL apoc.load.json("/Users/mpinto/.Neo4jDesktop/relate-data/dbmss/dbms-1f5f63ad-bba8-4673-8d16-2a3bd7299f65/import/countries.json") YIELD value
MERGE (longitude:Longitude {longitude: value.longitude})
WITH * WHERE value.native IS NOT NULL
MERGE (native:Native {native: value.native})
MERGE (timezones:Timezones {timezones: value.timezones})
MERGE (translations:Translations {translations: value.translations})
MERGE (name)-[:has_longitude]->(longitude)
MERGE (name)-[:has_native]->(native)
MERGE (name)-[:has_timezone]->(timezones)
MERGE (name)-[:has_translations]->(translations)
And the error is:
Property values can only be of primitive types or arrays thereof. Encountered: Map{zoneName -> String("Asia/Kabul"), gmtOffsetName -> String("UTC+04:30"), abbreviation -> String("AFT"), gmtOffset -> Long(16200), tzName -> String("Afghanistan Time")}.
I thinks is because of the json file:
"
timezones": [
{
"zoneName": "Asia\/Kabul",
"gmtOffset": 16200,
"gmtOffsetName": "UTC+04:30",
"abbreviation": "AFT",
"tzName": "Afghanistan Time"
}
],
I don't know how to put this in a cypher statement...
Thank you for your help!
Solved! Go to Solution.
12-15-2021 03:23 AM
This query works for me on the latest version of Neo4j:
CALL apoc.load.json("file://countries.json") YIELD value
MERGE (c:Country {code: value.numeric_code})
SET c += apoc.map.merge(apoc.map.removeKeys(value, ["timezones", "translations"]), value.translations)
WITH c, value
UNWIND value.timezones AS timezone
MERGE (t:Timezone {gmtOffset: timezone.gmtOffset})
SET t += timezone
MERGE (c)-[:HAS_TIMEZONE]->(t)
12-14-2021 03:10 AM
12-14-2021 09:01 AM
Hi! I tried to do that but now it appears that I need a WITH
Thank you.
Mariana
12-15-2021 02:22 AM
MERGE (timezones:Timezones {timezones: value.timezones})
WITH *
UNWIND value.timezones AS timezone
CREATE (t:Timezone) SET t += timezone
When I put it like this, the error is the same...
12-15-2021 02:29 AM
MERGE (timezones:Timezones {timezones: value.timezones})
Must be replaced by:
WITH *
UNWIND value.timezones AS timezone
CREATE (t:Timezone) SET t += timezone
12-15-2021 02:41 AM
12-15-2021 02:48 AM
Could you share the JSON file here please?
12-15-2021 02:51 AM
12-15-2021 03:23 AM
This query works for me on the latest version of Neo4j:
CALL apoc.load.json("file://countries.json") YIELD value
MERGE (c:Country {code: value.numeric_code})
SET c += apoc.map.merge(apoc.map.removeKeys(value, ["timezones", "translations"]), value.translations)
WITH c, value
UNWIND value.timezones AS timezone
MERGE (t:Timezone {gmtOffset: timezone.gmtOffset})
SET t += timezone
MERGE (c)-[:HAS_TIMEZONE]->(t)
12-15-2021 03:32 AM
I just put that code in and it actually works! Now I'll have to add it to the rest.
Thanks for your help!
All the sessions of the conference are now available online