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.

apoc.convert.fromJsonMap read JSON string

pavloN
Node Clone

I tried to do it

WITH apoc.convert.fromJsonMap(
      '
   [
      {"id": "1", "parentid": "2",
        "animal": 
        {
          "cat": ["One", "Two"],
          "dog": []
        }
      },

 {"id": "3", "parentid": "4",
        "animal": 
        {
          "cat": ["Tt", ""],
          "dog": ["ss"]
        }
      }

]
    
    '
    ) as v return v

There is the error:
Neo.ClientError.Procedure.ProcedureCallFailed: Failed to invoke function apoc.convert.fromJsonMap: Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of java.util.LinkedHashMap out of START_ARRAY token

But, it works:

WITH apoc.convert.fromJsonMap(
      '
      {"id": "1", "parentid": "2",
        "animal": 
        {
          "cat": ["One", "Two"],
          "dog": []
        }
      }
    '
    ) as v return v

How could it be fixed?

1 ACCEPTED SOLUTION

The JSON fragment you have there is a JSON list, not a JSON map (notice the outermost square brackets). Use apoc.convert.fromJsonList()

View solution in original post

2 REPLIES 2

The JSON fragment you have there is a JSON list, not a JSON map (notice the outermost square brackets). Use apoc.convert.fromJsonList()

Thank you @andrew.bowman! It works!!