I've got this JSON data that looks like this:
[
{
"loginId": "7638749",
"customerprofileDetails": {
"securityQuestions": [
"What is your favorite sports team?",
"What is your favorite song?",
"Who is your favorite artist?"
]
}
}
]
I have a script where I pass in that file as the first argument. The script looks like this:
for json in `cat $PWD/$1 | jq -cr '.[]'` ; do
echo "$json"
done
For some reason, when I run this script, it outputs this:
> fileFromJson.sh tmp2.json
{"loginId":"7638749","customerprofileDetails":{"securityQuestions":["What
is
your
favorite
sports
team?","What
is
your
favorite
song?","Who
is
your
favorite
artist?"]}}
Why are those newlines there and what's causing this problem? When I just run cat $PWD/tmp2.json | jq -cr '.[]'
, it prints out on one line. I'm using MacOS if that matters.