Parse JSON from Google Spreadsheet Parse JSON from Google Spreadsheet json json

Parse JSON from Google Spreadsheet


The "text" inside the $t attribute is not JSON. According to the documentation, text nodes are transfomed in to $t attributes, so you cannot rely on anything in there being properly formatted JSON.

I would suggest using a regular expression instead, though I will warn you that to parse that output will require some fancy stuff. You'll end up using an assertion since you can't split on commas - you'll have to search for (\w+): but in order to find the next element, you'll have to take in everything up to another matching (\w+):, but also not gobble it up. It can be done.


Just recently, I had the very same problem.

To parse content of $t, you can use this RegEx:

/(\w+): (.+?(?=(?:, \w+:|$)))/mgi

it will return pairs of key-value.

JavaScript example:

    var currentPropertiesText = jsonEntry['content']['$t'];    // var propsArray = currentPropertiesText.split(", ");    var re = /(\w+): (.+?(?=(?:, \w+:|$)))/mgi;    var propsArray = re.exec(currentPropertiesText)    var props = {};    while (propsArray != null) {        var propName = propsArray[1];        var propValue = propsArray[2];        props[propName] = propValue;        propsArray = re.exec(currentPropertiesText);    }

That should help :-)