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

How to join a string onto the output from an array

Let’s say this is my output from an aws-cli command.

{
    "imageIds": [
        {
            "imageDigest": "sha256:9"
        },
        {
            "imageDigest": "sha256:5"
        },
        {
            "imageDigest": "sha256:46",
            "imageTag": "latest"
        }
    ]
}

Using:

--query="imageIds[?imageTag != 'latest'].imageDigest"

Gives me ["sha256:9", "sha256:5", "sha256:46"].

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

How do I join an additional string to that list, either using the query, jq or bash, so it looks like
["X sha256:9", "X sha256:5", "X sha256:46"]?

>Solution :

$ echo '["sha256:9", "sha256:5", "sha256:46"]' | jq 'map("X " + .)'
[
  "X sha256:9",
  "X sha256:5",
  "X sha256:46"
]

Note that strings are delimited with double quotes, not single quotes.

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