0

I have a JSON file (array) like this:

[
  {"name":"Joe","age":36},
  {"name":"John","age":14},
  {"name":"Linda","age":62}
]

And I want to parse it in shell, analyzing every item in the array, then to run a command for each item:

curl 'http://example.com/submit' -H --data 'name=[NAME]&age=[AGE]' 

Which is, in this case:

curl 'http://example.com/submit' -H --data 'name=Joe&age=36'
curl 'http://example.com/submit' -H --data 'name=John&age=14'
curl 'http://example.com/submit' -H --data 'name=Linda&age=62' 

I know how to do it with Node.jS but I really want to know how to achieve such operations in bash.

I am using zsh on ubuntu.

Jeff Schaller
  • 66,199
  • 35
  • 114
  • 250
AGamePlayer
  • 7,415
  • 16
  • 46
  • 55
  • Possible duplicate of [How to parse JSON with shell scripting in Linux?](https://unix.stackexchange.com/questions/121718/how-to-parse-json-with-shell-scripting-in-linux) ... then use xargs – muru Oct 18 '19 at 03:06
  • 1
    ```curl 'http://example.com/submit' -H --data 'name=[NAME]&age=[AGE]' | php -r 'var_dump(json_decode(stream_get_contents(STDIN)));' ``` – hanshenrik Oct 18 '19 at 10:43

0 Answers0