Forum Discussion

sobha353's avatar
sobha353
New Contributor
2 years ago
Solved

JSON Formatting - Mapping Key and Value

I have a pipeline which reads data from source in JSON format and below is the format of json data retrieved. I am looking to map the values and not getting the desired result since the data is in string. Can anyone help on this please. Kindly advise.

"dataDetails": {
"data": "{"data":[{"First Name":"testfirstname1","Last Name":"testsecondname1","Status":"Active"},{"First Name":"testfirstname2","Last Name":"testsecondname2","Status":"Active"},{"First Name":"testfirstname3","Last Name":"testsecondname3","Status":"Active"}]}"

Mapper Expression used for mapping one of the above fields after Rest Get snap:
$data.mapValues((val, key) => (key == 'Status') ? val : ' '

  • Hi sobha353 ,

    You can parse the string as JSON using the JSON.parse() function in the mapper snap.

     

    JSON.parse($dataDetails.data)

     

    Hence, you can easily map the data as desired.
    Hope this helps!

    BR.
    Ivica

2 Replies

  • ivicakoteski's avatar
    ivicakoteski
    New Contributor III

    Hi sobha353 ,

    You can parse the string as JSON using the JSON.parse() function in the mapper snap.

     

    JSON.parse($dataDetails.data)

     

    Hence, you can easily map the data as desired.
    Hope this helps!

    BR.
    Ivica