I am using cURL
inside bash
to fetch json data from remote API. Also using jq
to parse and loop through the json array to perform additional operations. The response looks like this:
[ {"services": ["HOM" ],"specialServiceId": "APPOINTMENT","brandedName": "Appointment Home Delivery®","incompatibleSpecialServices": ["DATE","EVENING" ],"inputParameterRules": [ {"name": "PHONE_NUMBER","brandedName": "Appointment Phone Number","required": true,"format":"^\d{10,15}$","description": "A valid 10 to 15 digit phone number including area code and optional extension" } ] }, {"services": ["NDA_AM_EH","2DA" ],"specialServiceId": "NO_SIG","brandedName": "No Signature Required","categoryId": "DEL_CON","incompatibleSpecialServices": ["SIG","DIRECT_SIG" ],"inputParameterRules": [ {"name": "SIGNATURE_RELEASE_NUMBER","description": "A valid signature release number" } ],"specialServiceLevel": "ALLPKG" }, {...}, {...}]
As you can see the format
field inside inputParameterRules for PHONE_NUMBER contains a single backslash which makes this JSON un-parseable.
I would like to
- Either replace the single backslash with a double backslash before storing this json in a file OR
- Delete the format field.
Tried something like this:
SPECIAL_SERVICES_RESPONSE=$(curl -s -X GET -H "Authorization: Bearer ${BEARER_TOKEN}" "${SPECIAL_SERVICES_URL}" | jq '[.[].inputParameterRules[] | del(.format)]')
But it produces no results.
Thanks