How to concatenate 2 fields in JSON using JQ

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

See other online JQ resources

JQ PlaygroundJQ interactive tutorialJQ cheatsheetUsing Regex in JQ