httpPut json payload escaping

I'm having an issue making a simple json payload work for an API.

This curl works:

curl -X PUT "http://lac-00-0060/control/v1/jobs/6bdd1116-3c07-445d-a158-0a2aec6dbb6a" -H "accept: application/json" -H "Content-type: application/json" -d "{\"selected\":true}"

... and yes, if I remove the escaped quotes, the API tells me:

{
"detail": "Request body is not valid JSON",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}

... which is what I get from Ignition no matter how I build the payload:

params = {'\"selected\"': "false"}
or
params = {"\\\"selected\\\"": "false"}

Why is this not working?

Short of Wireshark, is there some way to inspect what is actually output?

Cheers!

Don't use httpPut. Use httpClient. There are numerous problems with the legacy functions.

Meanwhile, don't try to force the quotes in the dictionary that will become json, and don't supply strings for booleans. Let Ignition's json-encoder handle such things. So:

params = {"selected": False}

Note the use of jython's boolean.

3 Likes