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

5
  • don't know why are you providing xpath like this. you can put straightly like json.consents.id[0] Commented Jun 21, 2018 at 14:14
  • stackoverflow.com/questions/46551949/… Commented Jun 21, 2018 at 14:47
  • Because I need to provide Xpath from a variable. Commented Jun 22, 2018 at 6:51
  • Can you post the JSON document you're trying to parse? Commented Jun 23, 2018 at 1: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] Commented Jun 28, 2018 at 7:34

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.