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?

5
  • Duplicate of stackoverflow.com/questions/26717277/…? stackoverflow.com/questions/23118341/… ? Commented May 22, 2018 at 11:51
  • That method doesn't work with a URL it seems. Commented May 22, 2018 at 11:55
  • show some pseudo-code for your mentioned scenario I can do a loop around it to check for stuff Commented May 22, 2018 at 12:02
  • Why should it? jq parses files or stdin. URL is not a file. You can download the resource and save it to file by using curl and then pass to jq, for example like this: `curl localhost/status?json > tempfile; jq '.' tempfile'. Your asked about tuning json array into a bash array. Commented May 22, 2018 at 12:02
  • 1
    The temporary file is unnecessary; you want curl -s "$url" | jq . Commented May 22, 2018 at 12:09

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.