1

How can I merge objects within array?

{
  "input": [
    {
      "company_name": "Test",
      "property_space": 151821
    },
    {
      "company_name": "Test",
      "property_space": 145236
    }
  ]
}

I want to get an output like this

{
  "output": [
    {
      "company_name": "Test",
      "property_space": 297057
    }               
  ]
}
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83
Nurzat
  • 11
  • 2

1 Answers1

0

Mind that there is no proper grouping capacity build in JMESPath at the moment, although there is a proposition to offer one in a fork of the official repository. reference


But, if what you want to achieve is just to sum the property_space properties, then a way to do it would be:

{  
  "output": [
    {
      company_name: input[0].company_name, 
      property_space: sum(input[].property_space)
    }
  ]
}

Which, on your example JSON would indeed give you the expected

{
  "output": [
    {
      "company_name": "Test",
      "property_space": 297057
    }
  ]
}
β.εηοιτ.βε
  • 33,893
  • 13
  • 69
  • 83