1

My json like this from the command like curl https://sm.ms/api/upload:

{
  "code": "error",
  "msg": "No files were uploaded."
}

Now I want to get a text like this (all values of this json):

"error", "No files were uploaded."

I use the command curl https://sm.ms/api/upload | jq -r . but I can only get the json content. The document seems like not to support this funtion.

I search for the web for a long time but there's nothing helpful, so I hope you can help me and thank you~

acbetter
  • 188
  • 3
  • 9
  • 1
    Possible duplicate of [How to convert arbirtrary simple JSON to CSV using jq?](https://stackoverflow.com/questions/32960857/how-to-convert-arbirtrary-simple-json-to-csv-using-jq) – Jeff Mercado Apr 22 '18 at 18:57

2 Answers2

3

The output can be formatted as csv by using the --raw-output option:

jq --raw-output '"\"\(.code)\", \"\(.msg)\""'
Cole Tierney
  • 9,571
  • 1
  • 27
  • 35
2

You might like to consider a generic solution:

jq -r '[.[]] | @csv'
peak
  • 105,803
  • 17
  • 152
  • 177