Google Sheets API - Send JSON as a Cell Value

I’m trying to send into Google sheets a value for a cell which is a properly formatted JSON array. I keep getting the following errors from the Google Sheets API

"{\n \"error\": {\n \"code\": 400,\n \"message\": \"Invalid JSON payload received. Expected , or ] after array value.\\nN/A\\\", \\\"N/A\\\", \\\"[\\\\n\\t[\\\"Status\\\", \\\"Name\\\", \\\"Ma\\n ^\",\n \"status\": \"INVALID_ARGUMENT\"\n }\n}\n"

Through google searches I think the issue is that Google requires the JSON to be a 2 dimensional array, but I really have no idea.

The JSON is valid JSON as checked via JSONlint, so that is why I’m leaning toward the idea it needs to be a 2 dimensional array instead. I have the following JSON:

[{"index":1,"menu_item_uid":"1709289558668x372644769351072600","meal_type":"Dinner","notes":"adsf"},{"index":2,"menu_item_uid":"1709289558050x151363070630037280","meal_type":"Dinner","notes":"adsf"},{"index":3,"menu_item_uid":"1709289558668x372644769351072600","meal_type":"Lunch","notes":"adsf"},{"index":4,"menu_item_uid":"1709289557343x983533011446336100","meal_type":"Lunch","notes":"adsf"}]

I have no idea how to convert that to a two dimensional array or what a two dimensional array may even look like for the above JSON.

Has anybody successfully sent a JSON array through Google Sheets to add the JSON array to a single cell in the sheet? Or, does anybody know what the above JSON array would look like as a two dimensional array or has a link to a online converter so I could see the differences between the JSON array and two dimensional array?

1 dimension array: [1,2,3,4]
2 dimension array: [[1,2],[3,4]]
2 dimension arrays can be used to represent data on a 2d plane, like cells in a spreadsheet.

there are docs describing the expected request body of type ValueRange, and examples of creating ranges

Hopefully this should help you solve the problem

Is the below JSON array considered a 1 dimension array?

[{"index":1,"menu_item_uid":"1709289558668x372644769351072600","meal_type":"Dinner","notes":"adsf"},{"index":2,"menu_item_uid":"1709289558050x151363070630037280","meal_type":"Dinner","notes":"adsf"},{"index":3,"menu_item_uid":"1709289558668x372644769351072600","meal_type":"Lunch","notes":"adsf"},{"index":4,"menu_item_uid":"1709289557343x983533011446336100","meal_type":"Lunch","notes":"adsf"}]

yes, it’s a 1 dimension array of objects

1 Like