Install jq!
https://stedolan.github.io/jq/download/
-
Show a stream with curl: curl -s http://developer.usa.gov/1usagov
-
Pipe the output of that into jq:
curl -s http://developer.usa.gov/1usagov | jq .
But nothing shows up! Because of the buffer.
- Try again with "no buffer" parameter:
curl --no-buffer -s http://developer.usa.gov/1usagov | jq .
- Use jq to target a specific piece of the object. Let's go for the url (in the JSON schema it's called "u". Experiment with your own!):
curl --no-buffer -s http://developer.usa.gov/1usagov | jq .
- Now let's put that stuff in a file!
curl --no-buffer -s http://developer.usa.gov/1usagov | jq .u >>tester.txt
- What if we want multiple parameters?
curl --no-buffer -s http://developer.usa.gov/1usagov | jq '.u,.ll' >>multiple.txt
- What if we don't like buffering?
curl --no-buffer -s http://developer.usa.gov/1usagov | jq --unbuffered '.u,.ll' >>multiple2.txt
- What if we want a series of arrays?
curl --no-buffer -s http://developer.usa.gov/1usagov | jq --unbuffered --compact-output '[.u,.ll[]]' >>multiple4.txt
Go to Mike's GitHub page!
https://github.com/mikedewar/RealTimeStorytelling/tree/master/1