jq has two convenient ways to inspect an object’s keys:
| |
keys sorts the result. The jq manual describes keys_unsorted as returning keys roughly in insertion order. That makes it useful when inspecting a document, but it is weaker than a guarantee that every transformation will preserve an intended order.
If order matters to the application, put it in an array:
| |
Now jq '.[].name' follows an explicit sequence. A consumer does not have to infer a display order from the way an object happened to be written or reconstructed.
I would use keys_unsorted for a quick look at familiar input. For a report, API contract or reproducible export, I would define the ordering directly or sort by an explicit field.
Reference: jq manual: keys and keys_unsorted.