How to convert json to one line using jq

jq -c . file.json
  • -c means compact

For example:

[j@centos]~/tmp% jq -c . test.json 
{"name":"Tom","number":"212 555-1234","age":"21"}
[j@centos]~/tmp% 

Only select specified fields.

[j@centos]~/tmp% jq -r '.name + " " + .age' test.json
Tom 21

Or

[j@centos]~/tmp% jq -c '{NAME:.name,AGE:.age}' test.json
{"NAME":"Tom","AGE":"21"}