简体   繁体   中英

How to concatenate json result elements with JsonPath (JayWay)

I have this JSON response:

{
  "agreedToTermsOfUse": true,
  "firstName": "Admin",
  "lastName": "iConsulto",
  "middleName": "",
  "status": 0,
  "timeZoneId": "UTC",
}

and I am trying to concatenate the first name and the last name.

I have tried to do this:

$..concat($..firstName," ",$..lastName)

but it returns me an empty value. I have also try this:

$..concat("+",$..lastName)

And it has returned me this:

+["lastNameUser"]

Any ideas about why the second one option returns me something (like a list) and the first one doesn't return anything?? I have tried also this:

$..concat("+",$..lastName[0])

but it doesn't return me just the last name with the plus symbol.

So... How I can concatenate both names?? Thanks in advance!!!

Do not use deep scan .. operator while concatenating.

Try the below jsonpath-expression

$.concat($.firstName," ",$.lastName)

Online Tool : https://jsonpath.herokuapp.com/

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM