When using curl to edit a Gist: "message": "Problems parsing JSON"

Hey there. I’m trying to edit a Gist with JSON data and I’m constantly getting Problems parsin JSON. Tried to escape the double quotes with no success. I’m doing it like this because I actually use the output of a command but I’m trying to understand why Gist is not parsing the string correctly.


curl -v \
--request PATCH \
--data "$(
printf '{"files": {"im-latest-commit.json": {"content": "{\"field\":\"value\"}" }}}' \
)" \
--user x:x \

It appears to me that you have an outermost set of quotes that you aren’t accounting for:

--data "$(
printf '{"files": {"im-latest-commit.json": {"content": "{\"field\":\"value\"}" }}}' \

Specifically, the ones right after --data and at the end of the selection here. This means that your double-quotes like around files and im-latest-commit.json will need to be single-escaped and the ones in the JSON content itself will need to be double-escaped. Personally, I would recommend writing something like this in a dedicated scripting language like Ruby or Python.

I hope that helps!