I'm making calls to Azure DevOps API, and parsing the response with jq in a bash script. The JSON response contains whitespace in the form of new lines for some reason, and jq cannot handle and parse it.
E.g., I'm logging the response and it looks like this:
{"configuration":{"createdBy":{"displayName":"JohnSmith","url":"", ..... etc `jq gives me errors like
jq: parse error: Unfinished string at EOF at line 2, column 0jq: parse error: Invalid literal at line 2, column 0
It can't deal with the space between John and Smith
How can I clean this response up so that jq can handle it?
My script:
checksResponse=$(curl -s -H "$headers" -X GET "$policyChecksUrl")for check in $(echo "$checksResponse" | jq -r -c '.value[]'); do echo $check $(echo "$check" | jq -r '.configuration.id')doneMore complete response: I want to select an item by the id field, e.g. 174 and get the associated status field
{"value": [ {"configuration": {"createdBy": {"displayName": "John Smith","url": "https://url","_links": {"avatar": {"href": "https://dev.azure.com/thecompany/_apis/GraphProfile/MemberAvatars/aad" } },"id": "0eecda65-30dc-6b28-b497-8411e97df5b6","uniqueName": "js@thecompany.com","imageUrl": "https://dev.azure.com/thecompany/_api/_common/","descriptor": "aad.MGVlY2RhNjUtMzBkYy03YjI4LWI0OTctODQxMWU5N2RmNWI2" },"createdDate": "2023-01-10T14:52:24.7359941Z","isEnabled": true,"isBlocking": true,"isDeleted": false,"settings": {"minimumApproverCount": 2,"creatorVoteCounts": false,"allowDownvotes": false,"resetOnSourcePush": false,"requireVoteOnLastIteration": true,"resetRejectionsOnSourcePush": false,"blockLastPusherVote": false,"scope": [ {"refName": "refs/heads/master","matchKind": "Exact","repositoryId": "d416904f-641b-470a-9d" } ] },"isEnterpriseManaged": false,"_links": {"self": {"href": "https://dev.azure.com/thecompany/97f88eba-ecb2-484b-ae7c-c2d43a008cea/_apis/policy/configurations/173" },"policyType": {"href": "https://dev.azure.com/thecompany/97f88eba-ecb2fa4e907d-c16b-4a4c-9dfa-4906e5d171dd" } },"revision": 16,"id": 173,"url": "https://dev.azure.com/thecompany/97f88eba-ecb2-484b-ae7c-c2d43a008cea/_apis/policy/configurations/173","type": {"id": "fa4e907d-c16b-171dd","url": "https://dev.azure.com/thecompany/97f88eba-ecb2-484bc16b-4a4c-9dfa-4906e5d171dd","displayName": "Minimum number of reviewers" } },"artifactId": "vstfs:///CodeReview/CodeRev2f38956","evaluationId": "0c7b74ad661353ee2","startedDate": "2024-02-22T17:14:01.8987983Z","status": "queued","context": {} }, {"configuration": {"createdBy": {"displayName": "Jon Snow","url": "https://s-6ea05e3f7377","_links": {"avatar": {"href": "https://dev.azure.com/thecompany/_apis/GraphProfile/MemberAvatars/aad.YzZhNGMDVlM2Y3Mzc3" } },"id": "c6a4cf2d-0529-6a3d-88fb-6ea05e3f7377","uniqueName": "jonsnow@thecompany.com","imageUrl": "https://dev.azure.com/thecompany/_api/_common/identityIfb-6ea05e3f7377","descriptor": "aad.YzZhNGNmVhMDVlM2Y3Mzc3" },"createdDate": "2021-01-28T20:13:48.555187Z","isEnabled": true,"isBlocking": true,"isDeleted": false,"settings": {"requiredReviewerIds": ["b4704bd8fb603d" ],"minimumApproverCount": 1,"creatorVoteCounts": true,"scope": [ {"refName": "refs/heads/master","matchKind": "Exact","repositoryId": "d4169f-7210d2c5b1ad" } ] },"isEnterpriseManaged": false,"_links": {"self": {"href": "https://dev.azure.com/thecompany/97f88ebay/configurations/174" },"policyType": {"href": "https://dev.azure.com/thecompany/97f88eba-ecb2-8ec8-39368250530e" } },"revision": 1,"id": 174,"url": "https://dev.azure.com/thecompany/97f88eba-ecb2-484b-acy/configurations/174","type": {"id": "fd2167ab-b0be68250530e","url": "https://dev.azure.com/thecompany/97f88eba-ecb2-484b-ae7c-c2d43a008cea/_abe-447a-8ec8-39368250530e","displayName": "Required reviewers" } },"artifactId": "vstfs:///CodeReview/Ca%2f38956","evaluationId": "8a60f138-10c8-4838-81b4-031763798fdf","startedDate": "2024-02-22T17:12:38.7413814Z","status": "queued" } ],"count": 2}