Reputation: 59
I'm doing the following to capture some ADO JSON data:
iteration="$(az boards iteration team list --team Test --project Test --timeframe current)"
Normally, the output of that command contains a JSON key/value pair like the following:
"path": "Test\\Sprint1"
But after capturing the STDOUT into that iteration variable, if I do
echo "$iteration"
That key/value pair becomes
"path": "Test\Sprint1"
And if I attempt to use jq on that output, it breaks because it's not recognized as valid JSON any longer. I'm very unfamiliar with Bash. How can I get that JSON to remain valid all the way through?
Upvotes: 0
Views: 86
Reputation: 27225
As already commented by markp-fuso:
It looks like your echo
command is interpreting the backslashes. You can confirm this by running echo 'a\\b'
and looking at the output.
The portable way to deal with such problems is to use printf
instead of echo
:
printf %s\\n "$iteration"
Upvotes: 5