ContributionsMost RecentMost LikesSolutionsRe: How do i get JSON values from a response in Groovy Problem resolved. Typo only. Below is the working indexed code for future reference: package json import com.eviware.soapui.support.XmlHolder import groovy.json.* //define the location of the JSON file def response = context.expand( '${get_descendants#Response}' ).toString() //log.info(response) //define "json" which will be the name of my variable def json = new JsonSlurper().parseText (response) json.items.eachWithIndex { item, index -> log.info "totalResults: ${index}" log.info "Item resourceId: ${item.resourceId}" log.info "Item name: ${item.name}" log.info "Item resource type: ${item.resourceType}" log.info "Item status: ${item.status}" } Re: How do i get JSON values from a response in Groovy Thank you Rao. That makes perfect sense. This withEachIndex is exactly what I was looking for. I suspect this will help others as well. I am still throwing an error after many editing attempts. I've done some searching...not sure what is missing with a find or subsequent step. Thank you, again. I) Current JSON Parser package json import com.eviware.soapui.support.XmlHolder import groovy.json.* //define the location of the JSON file def response = context.expand( '${get_descendants#Response}' ).toString() //log.info(response) //define "json" which will be the name of my variable def json = new JsonSlurper().parseText (response) json.items.eachWithIndex { item, index -> log.inf "totalResults: ${index}" log.inf "Item resourceId: ${item.resourceId}" log.info "Item name: ${item.name}" log.info "Item resource type: ${item.resourceType}" log.info "Item status: ${item.status}" } II) Error Message thrown (if I comment out totalResults line same error occurs for subsequent lines): groovy.lang.MissingMethodException: No signature of method: org.apache.log4j.Logger.inf() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [totalResults: 0] Possible solutions: info(java.lang.Object), find(), any(), info(java.lang.Object, java.lang.Throwable), is(java.lang.Object), find(groovy.lang.Closure) Re: How do i get JSON values from a response in GroovyRe: How do i get JSON values from a response in Groovy This thread got me almost there:smileyvery-happy: I can parse the first level JSON correctly (thank you). The second level JSON, however, I am not getting counted as I had hoped I would. Any ideas on how to get the selected count to work? I) JSON File { "totalResults": 7, "limit": 100, "offset": 0, "items": [ { "resourceId": "33100000", "status": "active", "parentResourceId": "33000001", "resourceType": "BK", "name": "North", "language": "en", "timeZoneDiff": -102, "timeZone": "Eastern", "dateFormat": "mm/dd/yy", "timeFormat": "24-hour", "inventories": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33100000/inventories" }]}, "users": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33100000/users" }]}, "workZones": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33100000/workZones" }]}, "workSkills": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33100000/workSkills" }]}, "links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33100000" }, { "rel": "describedby", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/metadata-catalog/resources" } ] }, { "resourceId": "33200000", "status": "active", "parentResourceId": "33100000", "resourceType": "PR", "name": "BERTUZZI, Todd \t", "email": "33103@sunrise.demo", "phone": "555003310300", "language": "en", "timeZoneDiff": -102, "timeZone": "Eastern", "dateFormat": "mm/dd/yy", "timeFormat": "24-hour", "inventories": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33200000/inventories" }]}, "users": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33200000/users" }]}, "workZones": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33200000/workZones" }]}, "workSkills": {"links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33200000/workSkills" }]}, "links": [ { "rel": "canonical", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/resources/33200000" }, { "rel": "describedby", "href": "http://demo-ofsc.etadirect.com/rest/ofscCore/v1/metadata-catalog/resources" } ] }, { "resourceId": "33400000", "status": "active", "parentResourceId": "33100000", "resourceType": "PR", "name": "FIDDLER, Vernon", "email": "771002@sunrise.demo", "phone": "5555771002", "language": "en", "timeZoneDiff": -102, "timeZone": "Easte II) Working Groovy Script to "get" totalResults import com.eviware.soapui.support.XmlHolder import groovy.json.* //define the location of the JSON file def response = context.expand( '${get_descendants#Response}' ).toString() //define "json" which will be the name of my variable def json = new JsonSlurper().parseText (response) //grab that json file result I want log.info json.totalResults III) Non-Working Groovy Script to "get" resourceId package json import com.eviware.soapui.support.XmlHolder import groovy.json.* //define the location of the JSON file def response = context.expand( '${get_descendants#Response}' ).toString() //log.info(response) //define "json" which will be the name of my variable def json = new JsonSlurper().parseText (response) //grab that json file result I want log.info json[1].items.resourceId log.info json[1].items.name log.info json[1].items.resourceType log.info json[1].items.status Anyone see what is wrong here with the count? Re: api key & google maps I found a solution to the Google Maps authentication thanks to the SOAPUI Cookbook (kudos to you Rupert). The issue I was having was that I was using the template Google Maps REST call that I got as a packaged download. It was a great introduction to Google; however, as a package, it did not allow for additional fields to be added. To solve the problem, I created a new REST call using the APIs that were part of the download package. With the newly created REST call, it was easy to add the necessary additional fields including one for "key". Hope this helps someone else who downloads the Google Maps API package and hits a wall with authentication. -Will Re: api key & google maps As an alternate path to appending the API Key to the end of the REST call, I've been looking at creating an Oauth 2.0 connection. What I'm missing on this path is the Redirect URI. I don't know what to put there and don't see that anywhere in the forum or web. I've gotten the Client ID and Client Secret from Google and found the Authorization URI (https://accounts.google.com/o/oauth2/auth) and Access Token URI (https://accounts.google.com/o/oauth2/token). The last piece appears to be the Redirect URI and I'm not sure what to load in that field with SOAP UI. Maybe this is a bad path to go down or maybe it will work fine with a good Redirect URI. Thanks, Will Re: api key & google maps Thank you for looking. Yes, exactly, this is the problem. The problem is I need to build a little demo that will run through several thousand calls...I will exceed what the daily limit allows. I set up an account and have my API key from Google. I can use this API key with a browser and it works. Last step (and the one I need help with) is to get it added into the SOAP UI call. Google will charge my credit card. That's all fine...but I do need to be able to hit many, many times the volume allowed by the daily limit. The guidance from the SmartBear page almost gets me there... The difference between that page and my environment is in the property for the KEY. That's the hole...if I could append my call from SOAP UI Pro with that key that works in the browser then I'd be solid. Thank you again for your time and for looking at the screen shots and sharing the link. This is 98% of the way there I think...I'm just missing a way to append the call with the API KEY. Thoughts appreciated, Will Re: api key & google maps Yes I have seen this, thank you, it's a great piece. However, the response field is a bit different than the one in the example and that's where I'm stuck. I don't see a way to add a custom property that includes the key as this tutorial (#7) shows. It's like "a miracle occurs" in step 3 of part 7. I do believe that I'm doing something dumb. That's usually the case-I am very experienced in dumb things. You can see what I get in the response field (nothing that can be added there) and that I have exceeded quota. I've got a license key from Google and I can use it properly in a browser URL...I just can't find a way to shove that key into the end of the REST call. Thanks again, Will Re: Where can I hire a SoapUI consultant? Thanks all. The Groovy Script is just an example...I'm currently trying to get a Google API authentication going. I've put this on the forum as well. But, what I'm really looking for in this post, is someone willing to share an email address and their time (for a fee) for times when I get stuck. My best example is that I had a 50 line Groovy Script that was missing a single space. Syntax was killing me. That's all...it was missing a space and I kept coming back to it for two months when I had a few minutes trying to get it to work. When an expert looked at it, it took less than 5 minutes of that person's time and, bam, it was fixed. That guy isn't available but I'm thinking someone might be. I'm not a developer...I'm an application configuration guy who occasionally needs a bit of code to finish a project out. Or, in today's example, I need to reach out to Google API with an API Token. This is stuff that I suspect most community members can do well (probably in their sleep) but these are incredibly hard for me. Thanks, Will occasional consulting hours anyone? I'm looking for someone who can help me when I get stuck on a project. I am thinking a half hour one day maybe an hour on another day. Maybe a web-conference is all that is needed, maybe I need to pay for an hour of research. I am a sales engineer for a product that is the "master system of record for nothing". As a result, I use SOAP UI Pro to serve as middleware for the purpose of a demo. I generally keep to the simple stuff because I'm not a programmer and I'm relatively new to APIs. I get stuck and, as I get better, I get stuck at points that are beyond where my colleagues can help me. I have projects that have timelines (as we all do) and, after I search the web, I'm sometimes left with just a little bit more to do but unable to finish because I can't figure out the last step or two. Very frustrating. Currently, I'm looking for help with getting the Google API Key added to a call (or some legitimate Google authentication method into maps). I also have a 5-line Groovy script if/then statement that I need to define and additional property in. That's my need today but I will probably get stuck again in a week or two with another problem. As a sales engineer, every project I have has different needs and there is always a project or two or three that I've got on my plate. Getting stuck is part of the game but I now need someone outside my group to help me out. Thanks, Will