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

如何用jq将最简JSON转换为CSV或文本?实际提取需求求助

Solution to Extract JSON Values into Quoted, Comma-Separated Text

You're closer than you think! jq has exactly the tools you need to format the values this way—let's use the @csv filter, which handles quoting and commas automatically.

Here's the command you should run:

curl https://sm.ms/api/upload | jq -r '[.[]] | @csv'

Breakdown of what this does:

  • .[]: Iterates over all values in your JSON object (in this case, "error" and "No files were uploaded.")
  • [.[]]: Wraps those values into an array (required for the @csv filter to process them correctly)
  • @csv: Converts the array into CSV format, which automatically wraps each string in double quotes and separates them with commas
  • -r: Tells jq to output raw text instead of JSON-encoded strings, so you get clean "error","No files were uploaded." instead of extra escaped quotes

This will work even if your JSON has more key-value pairs later—it'll extract all values and format them the same way.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:45:23