0

Json Response after parsing

String Json= consents:[[id:740, duration:FixedPeriod, status:Active]], [[id:740, duration:FixedPeriod, status:Active]] [[id:740, duration:FixedPeriod, status:Active]] 

String Xpath = consents.id[0]

My Code as below

json = slurper.parseText(resvalue1.toString())  

 String[] XpathSplit = arSpRt[1].split(["\\."]) // xpath [0] is xpath od field in response
                    log.info "Xpath[1]"+ arSpRt[1]          // xpth[1] expected value of string


                log.info "XpathSplit  " + XpathSplit

                        for(j=0;j<XpathSplit.length;j++){
                        log.info "XpathSplit[j]  "+XpathSplit[j].toString()
                        json = json.(XpathSplit[j])                         
                             log.info "ActualValue ####" +json                      
                            }

So if I put only "consents.id" from a string its returning me all ids in consent array but I want consents.id[0] as first vale but its returning null

Bhanuchander Udhayakumar
  • 1,581
  • 1
  • 12
  • 30
Hanumant
  • 1
  • 3
  • don't know why are you providing xpath like this. you can put straightly like `json.consents.id[0]` – Bhanuchander Udhayakumar Jun 21 '18 at 14:14
  • https://stackoverflow.com/questions/46551949/how-to-get-key-from-arraylist-nested-in-json-using-groovy-and-change-its-value/46553716#46553716 – daggett Jun 21 '18 at 14:47
  • Because I need to provide Xpath from a variable. – Hanumant Jun 22 '18 at 06:51
  • Can you post the JSON document you're trying to parse? – craigcaulfield Jun 23 '18 at 01:25
  • Hi @craigcaulfield, I have already provided the sample above in the questions please find the same below. String Json= consents:[[id:740, duration:FixedPeriod, status:Active]], [[id:740, duration:FixedPeriod, status:Active]] [[id:740, duration:FixedPeriod, status:Active]] String Xpath = consents.id[0] – Hanumant Jun 28 '18 at 07:34

0 Answers0