cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Json Parsing issue in json generator

vaidyarm
Contributor

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 4

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:
image

Regards,
Viktor

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"
  }
]

vaidyarm
Contributor

is $ sign cant be used in JSON generator?

Why you donโ€™t just make this in Mapper?