Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to sort case insensitive using jq

Tags:

json

shell

jq

Does jq support case insensitive sorting?

for instance I have data.json like this

[
  {"title": "first", "description": "foo"},
  {"title": "Second", "description": "bar"}
]

simple jq 'sort_by(.title)' data.json returns

[
  {"title": "Second", "description": "bar"},
  {"title": "first", "description": "foo"}
]
like image 311
Mikhail Tokarev Avatar asked Apr 21 '26 13:04

Mikhail Tokarev


1 Answers

actually jq has built-in filters ascii_downcase and ascii_upcase you can use like this jq 'sort_by(.title | ascii_downcase)' data.json to get proper result.

[
  {"title": "first", "description": "foo"},
  {"title": "Second", "description": "bar"}
]
like image 185
Mikhail Tokarev Avatar answered Apr 23 '26 09:04

Mikhail Tokarev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!