Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to map the JSON to a field in Staging table.

Priyadharashin1
Tera Contributor

Hi All,

 

I need to map the inbound JSON value in a field in Staging table and then extract the values and map it into target table. When I map the value in staging table, it gets formatted but I need it to be a JSON. Any suggestions will be helpful. Thanks.

 

Value I get in Inbound: 

"workNotesHistory": [{ "workNote": "wdwd", "date": "23.02.2023 09:18:46", "user": " test", "order": 0 }]

 

Value in Staging table:

{workNotesHistory=[

{

workNote=wdwd,

date=23.02.2023 09:18:46,

user= test,

order=0

}]}

 

2 REPLIES 2

Sai Kumar B
Mega Sage

@Priyadharashin1 

While extracting the value in a field in the staging table do the parsing as var parseData = JSON.parse('<fetch the field value>'), and you've converted the field data to an object. Now you can extract the values from the parseData variable

If I could help you with my response you can mark it as helpful and correct as it benefits future viewers
Thanks,
Sai Kumar B
Community Rising Star 2023 & 2022

Hi Sai Kumar,

 

Yes I tried Parsing the field in Onbefore script and field mapping..but its not working only

{workNotesHistory=[

{

workNote=wdwd,

date=23.02.2023 09:18:46,

user= test,

order=0

}]}

 

here is the code:

var json = source.u_worknotes_history;

var parser = JSON.parse(json);
var testValue1Arr = [];
gs.info("PV transform scripr"+ parser);
for(var i=0;i<parser.workNotesHistory.length;i++){
testValue1Arr.push(parser.workNotesHistory[i].workNote+' - ' + parser.workNotesHistory[i].date + ' - ' + parser.workNotesHistory[i].user + '\n' + '');

}

target.work_notes = testValue1Arr.toString();