Monday, 26 August 2013

Convert large text block to json block

Convert large text block to json block

I have a BASH script that attempts to capture the output of
build/deployment logs and insert them into a Jira ticket using Jira's REST
API and CURL:
curl -v -X POST \
-H "Content-Type: application/json" \
--data "@header.json" \
--data "@log.txt" \
--data "@footer.json" \
-H "Authorization:Basic ABC123!@#" \
https://companyname.jira.com/rest/api/latest/issue/FOO-1234/comment
My problem is that the logs contain all manner of JSON tokens, which
causes the insert to fail. Is there a way from BASH to clean up the text
blob before posting to escape out all the illegal characters? Or a way to
say "don't parse anything in this block" or similar? Worst case, I'll
write some really scary AWK.

No comments:

Post a Comment