You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

CURL响应处理:如何手动打开请求返回JSON中的链接

Hey there! Let's cut out the manual copy-paste grind and get those links opened smoothly. Here are some practical, actionable ways to tackle this:

  • Extract links cleanly with jq (Linux/macOS)
    If you have jq installed (grab it via brew install jq on macOS or sudo apt install jq on Debian/Ubuntu), you can parse the JSON response directly to pull out all links. For example, if your links live in a links array under the data key:

    curl https://your-api-endpoint.com | jq -r '.data.links[]'
    

    The -r flag outputs raw strings (no extra quotes around links), making them ready to use right away.

  • Automatically open all links in one go
    Once you can extract the links, pipe them to your system's default browser command to skip manual opening:

    • On macOS:
      curl https://your-api-endpoint.com | jq -r '.data.links[]' | xargs open
      
    • On Linux:
      curl https://your-api-endpoint.com | jq -r '.data.links[]' | xargs xdg-open
      

    This will launch each link in your default browser automatically.

  • Windows PowerShell alternative
    If you're on Windows, skip third-party tools and use PowerShell's built-in JSON parsing:

    # Fetch the JSON response
    $apiResponse = Invoke-RestMethod -Uri "https://your-api-endpoint.com"
    # Loop through each link and open it
    foreach ($link in $apiResponse.data.links) {
        Start-Process $link
    }
    

    This will open every link in your default Windows browser without extra setup.

  • Manual fallback (no tools needed)
    If you don't want to install anything, copy the full JSON output from curl into a text editor with JSON formatting support (like VS Code with its built-in JSON extension). Format the JSON (usually Ctrl+Shift+I in VS Code), then locate the links field and copy-paste each link into your browser.

Just tweak the JSON path (.data.links[] in the examples) to match the actual structure of your API's response, and you're set!

内容的提问来源于stack exchange,提问作者Graj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 04:15:16