I am new to Javascript, so need some help with the below scenario.
I am reading a JSON input as shown below
var json_input = "[
{
"src_AccountId":["00100027H3QAK"],
"src_AccountName":["Vis Card Services","Vitoria Card Services SA"],
"src_MaxVus":[15,3],
"src_DocCount":[15,3]
},
{
"src_AccountId":["0010J000027lVFDQA2","6516983c9d71be4bcd799313"],
"src_AccountName":["Semiconductor Components","asdadasda"],
"src_MaxVus":[880,50],
"src_DocCount":[19,10]
}]";
How can I split & concatenate the input JSON data in order to get the below output? So basically I want 4 arrays each for AccountId, AccountName, MaxVus and DocCount. Also if there is more than 1 accountname for a particular accountid then I want only one accountname to be included in the result based on account which has highest value for MaxVus.
[
{
"AccountId": [
"00100027H3QAK",
"0010J000027lVFDQA2",
"6516983c9d71be4bcd799313"
],
"AccountName": [
"Vis Card Services",
"Semiconductor Components",
"asdadasda"
],
"DocCount": [
"15",
"19",
"10"
],
"MaxVus": [
"15",
"880",
"50"
]
}
]
Thanks
2
Answers
You need to parse the JSON first, then iterate over the objects within it, and construct the output in the structure you want.
Demo:
You can try:
Code Explanation: