How to map the JSON to a field in Staging table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-23-2023 03:11 AM
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
}]}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2023 12:11 AM - edited 02-26-2023 12:11 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-26-2023 12:23 AM
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();