recreate array with all items but the last

Advertisements

Given the following:

Input:

[
  [
    {
      "type": "strip",
      "output": "debian-7-x86_64-strip"
    },
    {
      "type": "compress",
      "output": "debian-7-x86_64-compress"
    },
    {
      "type": "full",
      "output": "debian-7-x86_64"
    }
  ],
  [
    {
      "type": "strip",
      "output": "debian-8-strip"
    },
    {
      "type": "compress",
      "output": "debian-8-compress"
    }
  ]
]

How to recreate the array with the last object item (from each sub-array) removed?

Desired Output:

[
  [
    {
      "type": "strip",
      "output": "debian-7-x86_64-strip"
    },
    {
      "type": "compress",
      "output": "debian-7-x86_64-compress"
    }
  ],
  [
    {
      "type": "strip",
      "output": "debian-8-strip"
    }
  ]
]

I’ve tried using things like ... |= .[:-1] and ...[to_entries | last], and ... | select(last|not) but I’m having no success.

Many thanks for the help.

>Solution :

.[][0:-1] gets you far, just missing the surrounding array in the output.

EDIT: [.[][:-1]] should do it.

Leave a ReplyCancel reply