Geckoboard Developer Community

SOLVED: Pushing a JSON gives "Invalid JSON" but... I think it's valid


Ok, I solved it! At the end indeed it was not a valid json. Solved with a simple JSON.stringify(payload)

Sorry guys, still a bit newbie here ^^

I’m trying to push a JSON from Google Scripts, but it’s returning 400 HTTP response.

This is an example of my JSON (I replaced the api_key for a fake one):
{“api_key”:“156462asd”,“data”:{“item”:[{“value”:“State of Sao Paulo”,“label”:“Region”,“color”:“60b8ec”},{“value”:“State of Minas Gerais”,“label”:“Region”,“color”:“60b8ec”}]}}

This is the response I’m getting:
{“message”:“Response body is empty or invalid JSON”}

From Google App Scripts I’m doing this request (I replaced the widget key, I’m inserting the good one in my script):

var url = ‘<my_widget_key>’;
var headers = { “Content-Type”:“application/json” };
var options = {
//‘muteHttpExceptions’: true,
‘method’: ‘post’,
‘headers’: headers,
‘payload’: payload
var response = UrlFetchApp.fetch(url, options);

The payload is the JSON object I show above. What am I doing wrong?

EDIT: I also tried to send the payload as JSON.stringify(payload) just in case, but then It’s returning “invalid syntax” on first item value.

Ok, I messed up with my JSON. “Value” should be an integer. I found out by trying to do a curl and it returned a “parseFloat” error.

Now, it works with curl, but still returns the same HTTP 400 error when trying to push it from Google Scripts. I’m using the exact same JSON that works with curl, so I don’t understand what is happening. This is the valid JSON:

{“api_key”:“asdasdasd”,“data”:{“item”:[{“value”:“588”,“label”:"",“color”:“60b8ec”,“region”:“Catalonia”},{“value”:“413”,“label”:"",“color”:“60b8ec”,“region”:“Community of Madrid”},{“value”:“48”,“label”:"",“color”:“60b8ec”,“region”:“Asturias”}]}}

The type of the widget is “Pie chart”. (I forgot to mention this, sorry)

Ok, I messed up again by adding a wrong column. But this one is the good one:

{“api_key”:“adasdasdas”,“data”:{“item”:[{“value”:34,“label”:“Mexico City”,“color”:“10b8ec”},{“value”:5,“label”:“Sinaloa”,“color”:“90b8ec”},{“value”:5,“label”:“Nuevo Leon”,“color”:“990b8ec”}]}}

Still the same error. With curl it works.

I’ll really appreciate any help.


Hello @xmfreak!
Glad you were able to sort it out. If you come across any other issues, please just let us know and we’ll be happy to help. :thumbsup:


I would be very grateful to know what your successful json formatting was as I am having exactly the same problem - also a newbie.
Bit of a long shot maybe after a year1


Hi @dixiechic, the right payload for the pie visualisation is:

	"item": [{
		"value": 34,
		"label": "Mexico City",
		"color": "10b8ec"
	}, {
		"value": 5,
		"label": "Sinaloa",
		"color": "90b8ec"
	}, {
		"value": 5,
		"label": "Nuevo Leon",
		"color": "990b8ec"

Which I’ve used to build this pie chart:

If you are receiving that error, my first guess would be that something is amiss with quotation marks or the escaping. Maybe you can share your payload?

That said, pie chart is a visualisation we don’t normally recommend for a dashboard. Here you can find out why :wink:


This is my attempt in Windows Powershell to send data to a Monitoring widget:
curl –Method Post –Uri –ContentType “application/json” -Body {“api_key”: “xxx”,“data”: “{“status”: “Up”, “downTime”: “9 days ago”,“responseTime”: “593 ms”}”}
I get curl : {“message”:“Response body is empty or invalid JSON”} in response.

I have tried SO many variations of escapes, quotes, spaces …
Many thanks in advance for any help you can give!


Just realised that cut and paste has removed all my escaping.
I had backslash before all double quotes in the Body.


I think the issue is that the JSON payload is being “stringified”, by that I mean that you are seemingly putting quotation marks before { within "data" (in other words "{ as opposed to { and the same for the closing })
… the right cURL should look like:

curl -X POST -d '{"api_key":"xxx","data":{
  "status": "Up",
  "downTime": "9 days ago",
  "responseTime": "593 ms"
}}' -H "Content-Type:application/json"

Which I have used to push data to this widget here:


Thanks. I had been playing around some more & did exactly that, removed those quotation marks. I also tried with and without the single quotes round the -d (-Body) part. The result was the same. This is the response I get:

curl : {“message”:“Response body is empty or invalid JSON”}
At line:1 char:1

  • curl -Method Post -Uri
  •   + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand


That’s odd. The correct native cURL is the one mentioned before

curl -X POST -d '{"api_key":"xxx","data":{
  "status": "Up",
  "downTime": "9 days ago",
  "responseTime": "593 ms"
}}' -H "Content-Type:application/json"

If you are still experiencing issues, I can only imagine they are Powershell specific. I’d recommend going through their documentation.

Invoke-WebRequest MSDN docs are here:

Invoke-RestMethod MSDN docs are here:

Alternatively, maybe you can use cURL (* ) instead


Thanks, yes I think it probably is a Powershell problem.
Will carry on experimenting & may try downloading curl.