How to concatenate json elements with JsonPath (JayWay)

11,167

Solution 1

The following would give AA1 as a result.

$.concat($.Keys[0].Format,$.Keys[0].Subtype)

Similarly

$.concat($.Keys[1].Format,$.Keys[1].Subtype) -- AA2
$.concat($.Keys[2].Format,$.Keys[2].Subtype) -- BA1

Solution 2

I know this post was a while ago but I'm searching for similar problems. Isn't this the solution?

  $.Keys[0].Format$.Keys[0].Subtype
  $.Keys[1].Format$.Keys[1].Subtype
  $.Keys[2].Format$.Keys[2].Subtype
Share:
11,167

Related videos on Youtube

gospodin
Author by

gospodin

Updated on June 04, 2022

Comments

  • gospodin
    gospodin almost 2 years

    Having a simple json:

    { "Keys": [
      {"Format": "A", "Subtype": "A1"},
      {"Format": "A",  "Subtype": "A2"},
      {"Format": "B",  "Subtype": "A1"}]
    }
    

    I would like to generate this result (Format + Subtype concatenation) using JsonPath expressions (without Java specific implementation):

     AA1
     AA2
     BA1
    

    Is it possible to concatenate the string elements using jsonPath?

    Thank you

  • gospodin
    gospodin over 6 years
    As I noted in my question, I am searching for a solution without Java specific implementation. External json format cannot be changed neither.