0

I have a URL http://localhost/status?json

Which is PHP-FPM's status page, it outputs this

{  
   "pool":"www",
   "process manager":"dynamic",
   "start time":1526919087,
   "start since":69780,
   "accepted conn":403320,
   "listen queue":0,
   "max listen queue":0,
   "listen queue len":0,
   "idle processes":21,
   "active processes":6,
   "total processes":27,
   "max active processes":200,
   "max children reached":1,
   "slow requests":0
}

I want to turn this JSON into an Array in Bash, so I can do a loop around it to check for stuff, I've heard JQ can parse this, but I'm unsure in BASH how I can convert it to a useable array.

Any ideas?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
  • Duplicate of https://stackoverflow.com/questions/26717277/converting-a-json-object-into-a-bash-associative-array? https://stackoverflow.com/questions/23118341/how-to-get-key-names-from-json-using-jq ? – KamilCuk May 22 '18 at 11:51
  • That method doesn't work with a URL it seems. – James Wilson May 22 '18 at 11:55
  • show some pseudo-code for your mentioned scenario *I can do a loop around it to check for stuff* – RomanPerekhrest May 22 '18 at 12:02
  • Why should it? jq parses files or stdin. [URL](https://en.wikipedia.org/wiki/URL) is not a file. You can download the resource and save it to file by using [curl](https://linux.die.net/man/1/curl) and then pass to jq, for example like this: `curl http://localhost/status?json > tempfile; jq '.' tempfile'. Your asked about tuning json array into a bash array. – KamilCuk May 22 '18 at 12:02
  • 1
    The temporary file is unnecessary; you want `curl -s "$url" | jq .` – tripleee May 22 '18 at 12:09

0 Answers0