JMES Expression To Extract and Concatenate Strings inside an array

45 Views Asked by At

Given this Json here

{
  "locations": {
     "name": "Seattle",
     "city": "SanFrancisco",
     "town": "SantaBarbara"
  }
}

I would need to obtain an array of strings like this with JMES Path

[
  "name=Seattle",
  "city=SanFrancisco",
  "town=SantaBarbara"
]

Is it possible using Jmes Path? Because if i start the expression like this it seems I always loose the key associated with my value

locations.*

And i obtain like this

[
  "Seattle",
  "San Francisco",
  "Santa Barbara"
]
1

There are 1 best solutions below

1
Vladimir Botka On

You can map the filter join if you create the array of arrays

[[`name`, name],
 [`city`, city],
 [`town`, town]]|map(&join(`=`, @), @)