Forum Discussion

vaidyarm's avatar
vaidyarm
Contributor
4 years ago

Json Parsing issue in json generator

I am trying to parse the below JSON in the JSON generator snap but getting the error.

Error: Expecting array for JSON-Path array index, found: Map

Payload :

[
{
“AccountId”: “9999”,
“FeatureName”: "test json -->>"$[0].UserIds[0]" test end "
}
]

It’s simple but still not getting through…

4 Replies

  • viktor_n's avatar
    viktor_n
    Contributor II

    Hi @vaidyarm,

    You can do it with Apache Velocity.

    [
      {
      #set( $a = "test json -->>" + $UserIds[0] + " test end ")
      "AccountId": "9999",
      "FeatureName": $a
      }
    ]
    

    Output:

    Regards,
    Viktor

    • vaidyarm's avatar
      vaidyarm
      Contributor

      Hey @viktor_n ,

      Actually, the problem is that “$[0].UserIds[0]” is not the value that I am trying to get from the pipeline, but it’s the text itself that is supposed to have $ signed value in it.
      (its the Mysql query which allows querying JSON data by SQL itself)
      https://dev.mysql.com/doc/refman/8.0/en/json-search-functions.html

      Text i want to parse : select testfield->>‘$[0].exploreUserIds[0]’ as testfield from sampletable

      Json through which i am trying to parse :

      [
        {
          "AccountId": "9999",
          "FeatureName": "select somefield->>'$[0].UserIds[0]' as testfield from sampletable"
        }
      ]
      
    • viktor_n's avatar
      viktor_n
      Contributor II

      Why you don’t just make this in Mapper?