I have an object with nested arrays which I:
- First turn into string using angular.toJSON() as ngCSV doesn't support nested arrays
- Then export as CSV file using ngCSV
- Then import and parse into JSON again using PapaParse.
The initial array looks like this:
filteredRecords [
{
date: '',
time: '',
comments: [
{message: '',
commenttime: ''},
{message: '',
commenttime: ''},
{message: '',
commenttime: ''}
],
arrival: '',
},
{
date: '',
time: '',
comments: [
{message: '',
commenttime: ''},
{message: '',
commenttime: ''},
{message: '',
commenttime: ''}
],
arrival: '',
}
]
After I've used angular.toJson() and done the export/import, the comment property looks like this:
filteredRecords [
{
date: '',
time: '',
comments: "[{"message":"wopwop","commenttime":"10.46"},{"message":"checkingin","commenttime":"10.46"},{"message":"tripletest","commenttime":"10.46"}]",
arrival: '',
}, ...
]
My problem is that I need to reverse the process and turn this string into an array after it's parsed, as my app needs to be able to read comment.message and comment.commenttime.
Any idea on how to proceed?
EDIT
I've managed to manually parse the string back into array using the solution from lex82, but I don't know how I could iterate into the main array and automatically do the same for all comments objects in every object from the array.
Any tips?