-1

How can I add, or modify if the element already exists, an element for each object in an array using jq?

For example going from:

[
    {
        "firstname": "Sophie",
        "lastname": "Haydock"
    },
    {
        "firstname": "Toussaint",
        "lastname": "Louverture"
    }
]

to

[
    {
        "firstname": "Sophie",
        "lastname": "Haydock",
        "common": "something"
    },
    {
        "firstname": "Toussaint",
        "lastname": "Louverture",
        "common": "something"
    }
]

This is different from the question marked as duplicate in that it adds an element to an object in an array rather than add an object to an array.

0

1 Answer 1

3

To do something with each element in an array, use map:

jq 'map(.common="something")'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.