2
我想用curl
命令创建一个包含JSON(有效的一个,我选中)的Gist,如here所述。创建JSON要点(冲突)
我第一次尝试这个脚本:
configText=$(cat jsonFile.json)
generate_post_data()
{
cat <<EOF
{
"description": "the description for this gist",
"public": true,
"files": {
"file1.txt": {
"content": $configText
}
}
}
EOF
}
curlBody="$(generate_post_data)"
curlResponse=$(curl -H "Content-Type: application/json" -X POST -d '$curlBody' https://api.github.com/gists)
这给了我错误Problems parsing JSON
,所以我试图直接通过该文件中的命令:
curl -H "Content-Type:application/json" -data-binary @jsonFile.json https://api.github.com/gists
但我得到同样的错误。我知道这必须是POST请求的JSON正文和我的文件的JSON(引号,括号......)之间的冲突。
如何发送干净的JSON文件到Gist?
OMG太感谢你了! – ilansas
我更新了我的帖子,其中保留了主要内容中的新行 –