gospodin
gospodin

Reputation: 1201

How to concatenate json elements with JsonPath (JayWay)

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

Upvotes: 5

Views: 19325

Answers (3)

Ruchika Goel
Ruchika Goel

Reputation: 49

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

Upvotes: 3

Tobias Cervin
Tobias Cervin

Reputation: 11

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

Upvotes: 1

Ankur Srivastava
Ankur Srivastava

Reputation: 923

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.

Upvotes: 0

Related Questions