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.

Capture values from a map that's in a list

Shukaku
Node Link

I need to create a node that has a latitude and longitude property.
Those values are in a map within a list called "locations".
I thought of a simple approach; create a loop and try indexing into it but I get an error (expected a map but was list).

WITH $json as jsonFile

FOREACH (x in jsonFile.response.landmarkAnnotations.locations |
   MERGE(n:Location {latitude: x.latLng.latitude, longitude: x.latLng.longitude}))

what other methods can I try and what can I read up on to give me an understanding of how to fix my problem?

Here's the json file

{
  "url": "https:\/\/farm5.staticflickr.com\/4469\/23531804118_fce6162cd1.jpg",
  "response": 
  {
    "labelAnnotations": 
    [
      {
        "score": 0.85065764188766,
        "mid": "\/m\/07yv9",
        "description": "vehicle"
      },
      ...
    ],
    "webDetection": 
    {
      "fullMatchingImages": 
      [
        {
          "url": "https:\/\/farm6.staticflickr.com\/5079\/7403056606_a09f6f670e_b.jpg"
        },
        ...
      ],
      "pagesWithMatchingImages": 
      [
        {
          "url": "http:\/\/picssr.com\/photos\/32622429@N02\/favorites\/page109?nsid=32622429@N02"
        },
        ...
      ],
      "webEntities": 
      [
        {
          "score": 3.0824000835419,
          "entityId": "\/m\/02vqfm",
          "description": "Coffee"
        },
        ...
      ],
      "partialMatchingImages": 
      [
        {
          "url": "https:\/\/farm6.staticflickr.com\/5079\/7403056606_a09f6f670e_b.jpg"
        },
        ...
      ]
    },
    "landmarkAnnotations": 
    [
      {
        "score": 0.78584295511246,
        "mid": "\/m\/02dpsq",
        "description": "Williamsburg Bridge",
        "locations": [ { "latLng": { "latitude": 40.712001800537, "longitude": -73.97216796875 } } ]
      },
      ...
    ]
  }
}

1 ACCEPTED SOLUTION

Hello @Shukaku and welcome to the Neo4j community

WITH $json AS jsonFile
UNWIND jsonFile.response.landmarkAnnotations AS la
MERGE (n:Location {latitude: la.locations[0].latLng.latitude, longitude: la.locations[0].latLng.longitude}))

Regards,
Cobra

View solution in original post

2 REPLIES 2

Hello @Shukaku and welcome to the Neo4j community

WITH $json AS jsonFile
UNWIND jsonFile.response.landmarkAnnotations AS la
MERGE (n:Location {latitude: la.locations[0].latLng.latitude, longitude: la.locations[0].latLng.longitude}))

Regards,
Cobra

Shukaku
Node Link

Hello, @Cobra, thank you!
This was valuable in understanding what I was missing!