Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 527

sort json object numerically by key

$
0
0

I have the following json format. It's basically a representation of the calendar:

{"month1": {"day1":{...}, "day2": {...}}, "month2": {...}}

I'd like to sort it such that both the months and the days will be in numeric order. The below input is the output of jq -S, but as you see it's sorted like: 1,10,2, and I'd like to sort it like 1,2,10. How can I do that with jq?

Input:

{"1":{"1":{"foo":"bar"},"10":{"foo":"bar"},"2":{"foo":"bar"}},"10":{"1":{"foo":"bar"},"10":{"foo":"bar"},"2":{"foo":"bar"}},"2":{"1":{"foo":"bar"},"10":{"foo":"bar"},"2":{"foo":"bar"}}}

Expected output:

{"1":{"1":{"foo":"bar"},"2":{"foo":"bar"},"10":{"foo":"bar"}},"2":{"1":{"foo":"bar"},"2":{"foo":"bar"},"10":{"foo":"bar"}},"10":{"1":{"foo":"bar"},"2":{"foo":"bar"},"10":{"foo":"bar"}}}

Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>