Search code examples
arrayselementjsonata

How to remove the first element of an array in JSONata?


How do I remove the first element of an array that looks like this:

{
  "array":[
    {
      "item":"1"
    },
    {
      "item":"2"
    },
    {
      "item":"3"
    }
  ]
}

I am expecting it to look like this:

{
  "array":[    
    {
      "item":"2"
    },
    {
      "item":"3"
    }
  ]
}

Solution

  • This can be accomplished via the $filter JSONata function:

    {
      "array": $filter(array, function ($v, $i) {
        $i != 0
      })
    }
    

    try it here: JSONata playground

    (edited to nest the output under the array key per the example output in the question)