How to capture values from JSON request and pass to response
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2016
08:34 AM
10-07-2016
08:34 AM
How to capture values from JSON request and pass to response
All,
I am working on REST service mocking. As part of this need to capture JSON request and from there capture few values and pass to response. Can anyone please help me how to do this ?
Thanks
Vis
2 REPLIES 2
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2016
07:55 AM
10-11-2016
07:55 AM
Hi
have a look at this http://docs.groovy-lang.org/latest/html/gapi/groovy/json/JsonSlurper.html
you will probably use something like this to get your json payload
def slurper = new JsonSlurper() def result = slurper.parseText(mockRequest.getRequestContent())
use an example from the link above to see how to get specific values
within your dispatch script set a property value to hold the respective json element value
context.setProperty( "PropertyName", JSONElementValue)
then within your response simply use ${PropertyName} where you want your inbound value to be returned
i.e.
{ "Request value" : "${PropertyName}" }
obviously using a naming convention that suits
hope that helps
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-29-2016
09:33 AM
11-29-2016
09:33 AM
It would be good if you can show the data that you are working with and what data do you need to extract.
Regards,
Rao.
Regards,
Rao.
