Search code examples
javarest-assuredrest-assured-jsonpath

RestAssured JsonPath: Issue with getting list from json


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"
      ]
   }

Solution

  • Finally found a solution for my question.

    .items*.find {it.key.startsWith('item')}.value