how.wtf

Write jq output to a file

· Thomas Taylor

If a user wants to write jq output to a file, the solution is simple.

jq output to a file

Extract all project ids from the following json payload to a text file:

 1{
 2  "projects": [
 3    { 
 4      "id": 1 
 5    },
 6    { 
 7      "id": 2
 8    }
 9  ]
10}
1echo '{"projects": [{"id": 1}, {"id": 2}]}' | jq '.projects[].id' > ids.txt

Output: ids.txt:

11
22

Using the redirection operator (>), the jq results are written to a file.

#Linux  

Reply to this post by email ↪