I have a database with various cells and values stored under each cell.
The cells in the database are: id, name, duration, date, and relationid.
This is the code I am currently using:
var result = {}
properties.data.forEach(addToResult); //Retrieves data from the database using properties.data
instance.data.datavarb = JSON.stringify(result); //Sends the converted data as JSON
function addToResult(pair,isjson){ //Operations
if(isjson===true) result[pair.key] = JSON.parse(pair.value); else result[pair.key] = pair.value;
}
I am encountering two issues:
1- First issue: This is how I retrieve the value after converting to JSON:
{"id":"1","name":"Football","duration":"12","date":"02-07-2018","relationid":null}
Desired format:
{id:1, name:"Football", duration:12, date:"02-07-2018", relationid:null}
I need to remove the quotes (""), specifically from the numbers (id, duration, and relationid) and their corresponding values.
2- Second issue: In the first problem, I only demonstrated one of the three values parsed from my database. What happens when I parse all three? Here is how it appears:
{"id":"1, 2, 3","name":"Football, France, Belgium","duration":"12, 4, 3","date":"02-07-2018, 08-07-2018, 10-07-2018","relationid":", 1, 1"}
Instead of creating individual entries for each set of values, it combines them into the same identifiers (id, name, duration). For my purpose, I require the following structure:
{id:1, name:"Football", duration:12, date:"02-07-2018", relationid:null},
{id:2, name:"France", duration:4, date:"08-07-2018", relationid:1},
{id:3, name:"Belgium", duration:3, date:"10-07-2018", relationid:1}
Thank you very much!!