Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort wont work on an Array of complex Objects #1254

Open
samer1977 opened this issue May 16, 2024 · 1 comment
Open

Sort wont work on an Array of complex Objects #1254

samer1977 opened this issue May 16, 2024 · 1 comment

Comments

@samer1977
Copy link

Hi ,

The sort spect or the the list sort function in the modify overwrite beta spec wont sort if the list is complex objects.

Example:

Input:

{
  "items": [
    {
      "2": "2 value"
    },
    {
      "1": "1 value"
    }
  ]
}

Sort Spec:

[
  {
    "operation": "sort"
  }
]

Output:


{
  "items" : [ {
    "2" : "2 value"
  }, {
    "1" : "1 value"
  } ]
}

Expected:


{
  "items" : [ {
    "1" : "1 value"
  }, {
    "2" : "2 value"
  } ]
}

Also if you try the sort function in the modify-overwrite-beta it wont work as well:

[
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "items": "=sort"
    }
  }
]

If the items array was simple array of ["2","1"] both spec will work. If items changed from an array to complex objects the sort spec will work! . Why only when its array of complex object it doesnt work. to me this is a bug.

@barbaros74
Copy link

barbaros74 commented May 23, 2024

Hi, Samer. Yes, sort is such a problematic, lacking operation, but yet a workaround might be given for some cases through use of some extra shift transformation spec for your current case such as

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "@": ".&3.&1.&"
          }
        }
      }
    }
  },
  {
    "operation": "sort"
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "&1[]"
      }
    }
  }
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants