apoc.convert.fromJsonMap read JSON string

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?

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

2 Likes

Thank you @andrew_bowman! It works!!