3

I have this inputJson:

[{"firstName": "Kancha", "lastName": "Cheena"},
{"firstName": "Harley", "lastName": "Quinn"}]

Expected output:

[{"fname":"Kancha", "value": "Kancha Cheena"},
{"fname":"Harley", "value": "Harley Quinn"}]

I am using an expression like this:

[*].{fname: firstName, value: firstName lastName}

Can you please suggest correcting this expression?

Ankit Gupta
  • 275
  • 3
  • 12

1 Answers1

11

You can use jmespath expression like

[*].{"fullName":join(``, [firstName, lastName])}

Which gives following result

[
  {
    "fullName": "KanchaCheena"
  },
  {
    "fullName": "HarleyQuinn"
  }
]

First parameter for the join function is the separator

Ganesh
  • 5,977
  • 5
  • 19
  • 25