Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 515

JSON payload in shell script using CURL [duplicate]

$
0
0

In my shell script, I'm reading a JSON array from a file. Then I'm looping over the array and send a POST request with each item from the array as json payload;

data.json

[  {"orderId": "abc111","amount": 2,"name": "item 1"  },  {"orderId": "abc222","amount": 5,"name": "item 2"  }]

tried like this;

jq -c '.[]' ./data.json | while read i; do        curl --location 'http://localhost:8080/endpoint' \    --header 'Authorization: Bearer xxx' \    --json $idone

unfortunately getting this error

{"message":{"statusCode":400,"message":"Unexpected end of JSON input","error":"Bad Request"},"status":400}{"message":{"statusCode":400,"message":"Unexpected end of JSON input","error":"Bad Request"},"status":400}

however, this works nicely;

curl --location 'http://localhost:8080/endpoint' \     --header 'Authorization: Bearer xxx' \      --json '{"orderId":"abc111","amount":2,"name": "item 1"       }'

how can I use JSON object in the loop to send as POST payload with CURL?


Viewing all articles
Browse latest Browse all 515

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>