How to concatenate 2 fields in JSON using JQ
Last modified: February 26, 2023
Suppose you have the following JSON input:
{
"firstName": "Charles",
"lastName": "Doe",
"age": 41,
"location": {
"city": "San Fracisco",
"postalCode": "94103"
},
"hobbies": [
"chess",
"netflix"
]
}
If you want to concatenate the firstName
and lastName
fields, you can do the following filter
{fullName: (.firstName + " " + .lastName)}
This will produce the following output:
{
"fullName": "Charles Doe"
}
You can try that example in our JQ playground here