1

Need to add array elements with same field name

Input:

[
  {
    "all": 1,
    "sys": "bus"
  },
  {
    "all": 14,
    "sys": "bus"
  }
]

I have tried like below:

.[] | (.all +.all)

but got result like

2
28

Expected result: 15 (1 + 14)

1 Answer 1

1

First map, then add:

map(.all) | add

C'est tout.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.