1

Can someone who familiar with jsonPath give me an advice how can i get a list of title from each item0, item1, item2 etc.

This query will return

findAll {it.key.startsWith('item')}

List of maps where key is item and value is body of item object and i don't know how to get List of titles

{
   "jcr:primaryType":"nt:unstructured",
   "item0":{
      "jcr:primaryType":"nt:unstructured",
      "tabType":"regular",
      "uniqueId":927,
      "hide":"no",
      "title":"title 0",
      "locales":[
         "Locale:en_us",
         "Locale:fr_ca",
         "Locale:es",
         "Locale:pt"
      ],
      "cq:tags":[
         "tag0"
      ]
   },
   "item1":{
      "jcr:primaryType":"nt:unstructured",
      "tabType":"regular",
      "uniqueId":445,
      "hide":"no",
      "title":"title 1",
      "locales":[
         "Locale:en_us",
         "Locale:fr_ca",
         "Locale:pt",
         "Locale:es"
      ],
      "cq:tags":[
         "Tag1"
      ]
   }
tom redfern
  • 30,562
  • 14
  • 91
  • 126
Roman
  • 91
  • 1
  • 10

2 Answers2

2

The syntax is a bit awkward but here's one way to do it:

findAll {it.key.startsWith('item')}*.getValue().title

Explanation:

First we find all entries whose keys starts with "item". For each entry we get its value (using the spread operator) and then get title.

Johan
  • 37,479
  • 32
  • 149
  • 237
0

Finally found a solution for my question.

.items*.find {it.key.startsWith('item')}.value 
Roman
  • 91
  • 1
  • 10