I have a response string like this:
|||COVID HPI^^^FEVER^^^Low Grade
|||COVID HPI^^^FEVER^^^Continuous
|||COVID HPI^^^RHINORRHEA/SNEEZING^^^No
|||GENERAL EXAM^^^CL^^^Conscious
|||GENERAL EXAM^^^ORIENTED^^^Yes
And i want to convert it into something like this:
{
"COVID HPI": [
{
"FEVER": "Low Grade, Continuous",
"RHINORRHEA/SNEEZING": "Yes"
}
],
"GENERAL EXAM": [
{
"CL": "Conscious",
"ORIENTED": "Yes"
}
]
}
I am not able to go beyond this without an ugly code:
const na = [];
fetch('http://localhost/test/json/newdata.json')
.then(response => {
let vv = response.json();
return vv;
})
.then(function(data){
console.log(data[0]['tRxVal'])
let nav = data[0]['tRxVal'].slice(3).split('|||');
let nbv = nav.map(function(item,i){
return item.split('^^^');
});
//console.log(nbv);
nbv.forEach(function(v,i){
if(!na.includes(v[0])){
na.push(v[0]);
}
})
console.log(na)
})
.catch(err => {
// handle errors
});
Can someone please help me with this Thanks