cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Property values can only be of primitive types or arrays thereof. Encountered: Map

Mariana
Node Clone

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!

1 ACCEPTED SOLUTION

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)

View solution in original post

9 REPLIES 9

Hello @Mariana

In your JSON, timezones is a list of dict so you have to UNWIND it:

UNWIND value.timezones AS timezone
CREATE (t:Timezone) SET t += timezone

Regards,
Cobra

Hi! I tried to do that but now it appears that I need a WITH
Thank you.
Mariana

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...

MERGE (timezones:Timezones {timezones: value.timezones}) 

Must be replaced by:

WITH *
UNWIND value.timezones AS timezone
CREATE (t:Timezone) SET t += timezone

Could you share the JSON file here please?

countries.txt (345.4 KB)
Sure! I put it as txt because it does not let you upload with the json extension.

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)

I just put that code in and it actually works! Now I'll have to add it to the rest.
Thanks for your help!