[NOTE: The question has been clarified in accordance with the comments, some of which might therefore be outdated.]
I'm using jq to parse the following JSON:
[{
"type": "A",
"id": "A",
"name": "A",
"message": "OK",
"updateDate": "2018-07-31T10:55:14.813Z",
"createDate": "2018-07-31T08:01:32.164Z",
"status": "ACTIVE"
}, {
"type": "B",
"id": "B",
"name": "B",
"message": "OK",
"updateDate": "2018-07-31T10:55:16.803Z",
"createDate": "2018-07-31T08:01:34.171Z",
"status": "ACTIVE"
}, {
"type": "C",
"id": "C",
"name": "C",
"message": "OK",
"updateDate": "2018-07-31T10:55:18.607Z",
"createDate": "2018-07-31T08:01:37.181Z",
"status": "ACTIVE"
}, {
"type": "D",
"id": "D",
"name": "D",
"message": "OK",
"updateDate": "2018-07-31T10:55:20.877Z",
"createDate": "2018-07-31T08:01:38.185Z",
"status": "ACTIVE"
}, {
"type": "E",
"id": "E",
"name": "E",
"message": "OK",
"updateDate": "2018-07-31T10:55:18.615Z",
"createDate": "2018-07-31T08:01:44.207Z",
"status": "ACTIVE"
}, {
"type": "F",
"id": "F",
"name": "F",
"message": "OK",
"updateDate": "2018-07-31T10:55:19.131Z",
"createDate": "2018-07-31T08:01:44.207Z",
"status": "ACTIVE"
}, {
"type": "G",
"id": "G",
"name": "G",
"message": "OK",
"updateDate": "2018-07-31T10:55:18.326Z",
"createDate": "2018-07-31T08:01:46.212Z",
"status": "ACTIVE"
}]
To display the name and the status I use the following commands, where $input
holds the above JSON:
output=$(jq '.[] | "\(.name) \(.status)"' <<< "$input")
echo $output
This produces:
"A: ACTIVE" "B: ACTIVE" "C: ACTIVE" "D: ACTIVE" "E: ACTIVE" "F: ACTIVE" "G: ACTIVE"
How do I ensure each iteration produces one new line, like so:
"A: ACTIVE"
"B: ACTIVE"
"C: ACTIVE"
"D: ACTIVE
"E: ACTIVE"
"F: ACTIVE"
"G: ACTIVE"