0

I’m running the curl command (with --compressed) and receiving the following response:

{"data":{"getByCode":{"details":{"images":[{"url":"https://pics.example.com/pics/pics1600x1200/example/1/189e2083-b33f-492f-8ef4-41f61a2c7e56.jpg","title":"Außenansicht"},{"url":"https://pics.example.com/pics/pics1600x1200/example/5/5f70963d-c15d-4cbb-80a2-63aed4f98720.jpg","title":"Außenansicht"},{"url":"https://pics.example.com/pics/pics1600x1200/example/f/fb74a1fb-b63b-4c2e-8a39-d4ecabf25276.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/d/decfc337-e0dc-4f8a-81f3-18d732d12551.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/0/0ee5fcad-20a6-4336-811a-e0c3198d6513.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/6/6b4ff2b5-9320-46b7-973d-9bb685920e37.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/9/92eef552-6ffd-4e75-828d-e0651620ccf5.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/6/6e35223b-1ee3-4b25-b9d5-232e52088f3b.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/6/69bbda2e-f3e4-4e9f-80e8-6173326c748c.jpg","title":"Pool"},{"url":"https://pics.example.com/pics/pics1600x1200/example/6/6028a718-96f8-43de-b20c-a3c17a37e6f5.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/f/f382cf15-2f69-46e7-af33-497e3f9d9c72.jpg","title":"POOL ROOF TOP"},{"url":"https://pics.example.com/pics/pics1600x1200/example/3/3430d458-5f6b-4513-a6cd-2d85770fa663.jpg","title":"Santa Rosa Grill"},{"url":"https://pics.example.com/pics/pics1600x1200/example/1/14c16080-992a-4a8f-b5d4-62d5e45f22f1.jpg","title":"ROOF TOP BAR"},{"url":"https://pics.example.com/pics/pics1600x1200/example/e/e5208f0c-1880-43d5-ba97-5aca2ddb4be2.jpg","title":"ROOF TOP BAR"},{"url":"https://pics.example.com/pics/pics1600x1200/example/1/18b68b07-b33d-4ff2-a103-f434eb62cc49.jpg","title":"ROOF TOP BAR"},{"url":"https://pics.example.com/pics/pics1600x1200/example/b/b2263932-5085-4591-81ca-d04660d5e951.jpg","title":"Areca"},{"url":"https://pics.example.com/pics/pics1600x1200/example/9/91da5532-9b03-4ecd-9177-007d8755bc11.jpg"}]}}}}

At the end of my command in terminal, is there something I could pipe these results to, that would make the output format just a list of extracted URLs? e.g.

https://pics.example.com/pics/pics1600x1200/example/1/189e2083-b33f-492f-8ef4-41f61a2c7e56.jpg
https://pics.example.com/pics/pics1600x1200/example/f/fb74a1fb-b63b-4c2e-8a39-d4ecabf25276.jpg
https://pics.example.com/pics/pics1600x1200/example/d/decfc337-e0dc-4f8a-81f3-18d732d12551.jpg
https://pics.example.com/pics/pics1600x1200/example/9/92eef552-6ffd-4e75-828d-e0651620ccf5.jpg
1
  • The command line 'jq' can extract data from JSON documents Commented Oct 7, 2019 at 14:24

2 Answers 2

2

jq, a lightweight and flexible command-line JSON processor.

Get it from the jq official website

Solution

<your-curl-command> | jq '.data.getByCode.details.images[].url' -r
# -r / --raw-output, used here to avoid quotation marks in the output
Sign up to request clarification or add additional context in comments.

3 Comments

curl … | jq '.data.getByCode.details.images[].url' -r. add -r for raw output
@LéaGris -r removes the quotation mark in this situation. Thanks for your advice.
Thank you so much jq was exactly what I was looking for :) I managed to get it to produce the results I was after by using: jq | grep -Eo '(http|https)://[^"]+'
0

You need jq tool that lets you read, filter, and write JSON in bash

after running your curl command add the following line .

curl-command | jq '.data.getByCode.details.images.[].url' -r

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.