directus-sync icon indicating copy to clipboard operation
directus-sync copied to clipboard

Sorting JSON when keys are the same

Open SidonieBouthors opened this issue 2 months ago • 3 comments

Is your feature request related to a problem? Please describe. We use the sortJson option to make sure our directus config works well in version control: the diffs only show what actually changes, not things being reordered. However we noticed that this option only sorts the keys. This makes sense, but we have encountered a scenario where several items have exactly the same keys. In particular we have in operations.json several items with these keys:

{
    "_syncId": "...",
    "flow": "...",
    "key": "event",
    "name": "Event",
    "options": {
      "collection": "events",
      "key": [
        "{{$trigger.payload.event}}"
      ]
    },
    "position_x": 1,
    "position_y": 1,
    "reject": null,
    "resolve": "...",
    "type": "item-read"
  },

Describe the solution you'd like It would be nice if items with exactly the same keys would then be sorted by some value (perhaps the ID ?) so that when using sortJson, we can truly expect no random reordering on a save

Describe alternatives you've considered We're considering adding a hook for this on our end, but this would make sense in the spirit of the sortJson option, since its main purpose is working better with version control

SidonieBouthors avatar Oct 26 '25 08:10 SidonieBouthors

Hi @SidonieBouthors I don't understand. How can an object have the same key twice?

EdouardDem avatar Nov 04 '25 20:11 EdouardDem

I meant different objects having the same JSON keys, not the same object keys. When this occurs these object don't seem to always be sorted in the same order

SidonieBouthors avatar Nov 04 '25 20:11 SidonieBouthors

Can you show me an example ?

EdouardDem avatar Nov 12 '25 00:11 EdouardDem