Skip to content

Add the ability to have the fields sorted. #15

@SpicyLemon

Description

@SpicyLemon

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions