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
.
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