0

I'd like to know if there is a way to parse a cURL response without using PHP. Every example I've seen seems to explicitly use PHP.

  • I'm calling cURL within a bash script.
  • I cURL a URL and receive this XML response:

    {"name":"callINSTANCETESTJob","id":10900,"status":"COMPLETED","message":"The job has finished."}

My goal is to obtain the numeric value following "id" and setting it to a variable

EDIT:

my curl statement is as follows:

JOB_NAME=$1

request_url="https://127.0.0.1:8443/batch/$JOB_NAME"

curl -k -H "Content-Type: application/xml" $request_url | jq -r 'id.'
Josh
  • 341
  • 5
  • 26
  • Possible duplicate of [Parsing JSON with Unix tools](https://stackoverflow.com/questions/1955505/parsing-json-with-unix-tools) – hanshenrik Jul 09 '18 at 18:43

1 Answers1

0

that is not XML, that is JSON. try using jq to parse JSON, eg

curl (...) | jq -r '.id'

root@miner1:~# echo '{"name":"callINSTANCETESTJob","id":10900,"status":"COMPLETED","message":"The job has finished."}' | jq -r '.id'
10900
root@miner1:~#
hanshenrik
  • 19,904
  • 4
  • 43
  • 89
  • Sorry for mistake. Thank you, what if I want to assign the results to a variable? – Josh Jul 09 '18 at 19:37
  • I've got it figured out. Thank you for the response. I've marked your answer as correct. – Josh Jul 09 '18 at 20:06