Similar to providing the --sort-keys flag to jq, it'd be nice to be able to have the fields of an object sorted alphabetically in the output of json_info. However, the array indexes should still be sorted numerically, so it's not as simple as just using the sort program.
For example:
The command
> jq '[range(0;11)|{"val":.,"str":(.|tostring)}]' -n | json_info -r -p '.[9]' -p '.[10]' -
outputs
.[9] = object: 2 keys: ["val","str"]
.[9].val = number: 9
.[9].str = string: "9"
.[10] = object: 2 keys: ["val","str"]
.[10].val = number: 10
.[10].str = string: "10"
Note that the "val" field line is before the "str" field line.
The command
> jq '[range(0;11)|{"val":.,"str":(.|tostring)}]' -n | json_info -r -p '.[9]' -p '.[10]' - | sort
outputs
Note that the 10th element of the array is now listed before the 9th.
Desired output:
.[9] = object: 2 keys: ["str","val"]
.[9].str = string: "9"
.[9].val = number: 9
.[10] = object: 2 keys: ["str","val"]
.[10].str = string: "10"
.[10].val = number: 10
In the above, the ordering of the keys in the object line (e.g. the ["str","val"] in .[10] = object: 2 keys: ["str","val"]) isn't as important as the line ordering. The line ordering is the primary thing desired here.
Similar to providing the
--sort-keysflag tojq, it'd be nice to be able to have the fields of an object sorted alphabetically in the output ofjson_info. However, the array indexes should still be sorted numerically, so it's not as simple as just using thesortprogram.For example:
The command
outputs
Note that the "val" field line is before the "str" field line.
The command
outputs
Note that the 10th element of the array is now listed before the 9th.
Desired output:
In the above, the ordering of the keys in the object line (e.g. the
["str","val"]in.[10] = object: 2 keys: ["str","val"]) isn't as important as the line ordering. The line ordering is the primary thing desired here.