5

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
  • 1,133
  • 4
  • 22
  • 42

3 Answers3

3

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
David Buck
  • 3,752
  • 35
  • 31
  • 35
1

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
0

You can frame JSON path expressions like:

$.Keys[0].Format -- A
$.Keys[1].Format -- A
$.Keys[2].Format -- B

and refer to this SO thread the below link to eventually parse it using Jayway.

Ivan
  • 34,531
  • 8
  • 55
  • 100
Ankur Srivastava
  • 855
  • 9
  • 10
  • 1
    As I noted in my question, I am searching for a solution without Java specific implementation. External json format cannot be changed neither. – gospodin Aug 29 '17 at 14:31