I need a jq filter that would:
- when given
{"a": [3, 1, 2]}, produce{"a": [1, 2, 3]} - when given
{"b": 0}, produce{"b": 0}
.a |= sort doesn’t work in the second case, because “null (null) cannot be sorted, as it is not an array”.
From the manual I figured .a |= try sort should work. When .a is an array, it should just sort it. When .a is null, try should catch the error from sort and produce nothing, thus deleting "a". This works for {"b": 0}, but for {"a": [3, 1, 2]} it produces {} instead. Why?
I know other ways to accomplish this, but I want to understand why mine doesn’t work.
>Solution :
It’s a bug in JQ 1.6, first reported here in 2019.