Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

recreate array with all items but the last

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading