我正在运行curl命令(使用--compressed
)并收到以下响应:
{"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"}]}}}}
在终端中命令的末尾,是否可以通过管道传输这些结果,从而使输出格式仅是提取的URL的列表?例如
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
答案 0 :(得分:2)
jq
,一种轻巧灵活的命令行JSON处理器。
<your-curl-command> | jq '.data.getByCode.details.images[].url' -r
# -r / --raw-output, used here to avoid quotation marks in the output
答案 1 :(得分:0)
您需要 jq 工具,该工具可让您在bash中读取,过滤和写入JSON
在运行curl命令之后,添加以下行。
curl-command | jq '.data.getByCode.details.images.[].url' -r