如何用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@csvfilter 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
相关产品推荐
相关产品推荐

