0

I'm wondering if it's possible to sort or bring the min value in case of an array of json. I read something about this issue but found nothing.

This is the Input:

{
  "intData": [
    {
      "DATE": "2018",
      "NOME": "raf"
    },
    {
      "DATE": "2001",
      "NOME": "fabio"
    },
    {
      "DATE": "2002",
      "NOME": "fabiola"
    }
  ]
}

I would:

{
  "intData": [
    {
      "DATE": "2001",
      "NOME": "fabio"
    },
    {
      "DATE": "2002",
      "NOME": "fabiola"
    },
    {
      "DATE": "2018",
      "NOME": "raf"
    }
  ]
}

or

{
  "DATE": "2001",
  "NOME": "fabio"
}

Is it possible?

1 Answers1

1

Ordered Results

The steps are as follows:

  1. Create object with structure: $.DATE.NOME.@
  2. Sort it
  3. Turn it back into an array
[
  {
    "operation": "shift",
    "spec": {
      "intData": {
        "*": {
          "@": "@(1,DATE).@(1,NOME)"
        }
      }
    }
  },
  {
    "operation": "sort"
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "@": "intData.[]"
        }
      }
    }
  }
]

First result

The steps are as follows:

  1. Create object with structure: $.DATE.NOME.@
  2. Sort it
  3. Turn it back into an array
  4. Get first result
[
  {
    "operation": "shift",
    "spec": {
      "intData": {
        "*": {
          "@": "@(1,DATE).@(1,NOME)"
        }
      }
    }
  },
  {
    "operation": "sort"
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "@": "[]"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "0": {
        "@": ""
      }
    }
  }
]
Community
  • 1
  • 1
Matthew Warman
  • 3,234
  • 2
  • 23
  • 35