How to sort a json file by keys and values of those keys in jq

Ok with some assistance on the IRC channel I’ve found an answer.

Basically, it looks like this:

jq \
  '.components.rows|=sort_by(.id)|.components.rows[].properties|=sort_by(.name)' \
  file.json > out.json

Select the right object,
walk into arrays if needed,
then sort_by a single value.

I was trying sort_by(.components.rows.id) which failed.

|= instead of | passes the values along instead of stripping them.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)