I have developed a Google Application Script that generates data for Tabulator.js from a Google Sheet as a string. When I insert this text directly into my HTML file, it works fine. However, when I try to load it via a Google Application Script call and assign the string to the Tabulator's data variable, I encounter an error message:
Data Loading Error - Unable to process data due to invalid data type Expecting: array , Received: string
Is there a straightforward way to convert this string into the required JSON array structure? Please note the use of children
in the first row. You can experiment with it on jsFiddle.
I have tried using JSON.parse
, but it seems like the syntax of the string is not correct:
SyntaxError: JSON.parse: expected property name or '}' at line 1 column 2 of the JSON data"
[
{id:1, name:"BalanceOil", _children:
[
{id:2, name:"BalanceOil+ s testy", cena:31},
{id:3, name:"BalanceOil+ ", cena:31}
]
},
{id:11, name:"Xtend x2 Kit", cena:23},
{id:18, name:"Viva+ Kit", cena:21}
]
The original data appears more complex, but I have simplified it here.
[{id:1, name:"BalanceOil", _children:
[{id:2, name:"BalanceOil+ s testy", cena:31, mn:1,cena_1:"", package:159, kredityMesicne:4, kredityBalik:14},
{id:3, name:"BalanceOil+ ", cena:31, mn:1,cena_1:"", package:85, kredityMesicne:4, kredityBalik:8},]},
{id:11, name:"Xtend x2 Kit", cena:23, mn:1,cena_1:"", package:83, kredityMesicne:3, kredityBalik:8},
{id:18, name:"Viva+ Kit", cena:21, mn:1,cena_1:"", package:60, kredityMesicne:3, kredityBalik:4}
]
Can I use the data source as a string, or do I need to modify the code and create the structure as the desired object type? Should it be an array or JSON format?