Help
cancel
Showing results for 
Search instead for 
Did you mean: 
Copilot Lvl 2
Message 1 of 2

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.

 

#!/bin/bash

curl -v \
--request PATCH \
--data "$(
printf '{"files": {"im-latest-commit.json": {"content": "{\"field\":\"value\"}" }}}' \
)" \
--user x:x \
https://api.github.com/gists/x
1 Reply
Community Manager
Message 2 of 2

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

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!