Dark theme | Light theme

October 5, 2023

jq Joy: Reverse An Array

jq is a powerful tool to work with JSON from the command-line. The tool has a lot of functions that makes our live easier. To simply reverse the order of elements in an array we can use the reverse function. The values in the input array are reversed and returned in the output array.

In the following example we use the reverse function for an array:

$ jq --null-input --compact-output '[1, 2, 3, 4, 5] | reverse'

Written with jq 1.7.