I'm calling in data from the Google Sheets API, and each row's content looks like this:
{
$t: "title: Test Title, gamelabel: Test Game, startdate: 2016-06-14"
}
Is there any off-the-shelf / easy way to turn this string into a javascript object in this format?
{
title : 'Test Title',
gamelabel: 'Test Game',
startdate: '2016-06-14
}
Note, the keys need to be dynamic (creating keys for whatever the sheets' heading is), so knowing exactly what keys will be in $t
isn't possible.
Update: Using JSON.parse()
doesn't work here, I suppose there's a hacky-ish way of doing this via:
var temp = {};
var params = $t.split(/:/g);
for(var i = 0; i<params.length; i += 2){
temp[params[i].trim()] = params[i + 1].trim();
}
This doesn't actually work for the supplied format / is potentially a start but I dunno what's the best practice here.