Ask a Question

How to update a JSON request body

mwalter
Occasional Contributor

How to update a JSON request body

Hi,

I'm trying to update part of a Json REST request.  Below is the json in question and I need to update the last row (OpenTaxFilters) to add values.  I haven't really seen anything out there that anyone has done equivalent to this, but I'm expecting it must have been done.  Anyone have any ideas on how I could go about this?

 

"GetOpenTaxLotsByAccount": {
"AccountNumber": "54007070",
"SecurityNumber": "",
"PriceIndicator": "",
"OpenTaxFilters": {"HeldAwayIn": ""}

 

Thanks,

Mike

5 REPLIES 5
New2API
Frequent Contributor

Hello, have you tried JsonBuilder?

 

Assumption: Initial JSON output is a response from a REST call or a pre-prepared JSON template

 

for ex:

import groovy.json.JsonBuilder

 

def JSON = context.expand('${TestStepName#Response}').toString()

      NEWJSON = new JsonBuilder(JSON)

     

NEWJSON.content.OpenTaxFilters.HeldAwayIn = "Put desired value here"

 

log.info NEWJSON

 

Hope this helps!

 

      

 

 

PaulMS
Super Contributor

Hi Mike

 

You could use a custom property to store the value you want to work with for OpenTaxFilters.

 

The property can be accessed from a script and used in the request body.

https://www.soapui.org/functional-testing/properties/working-with-properties.html

mwalter
Occasional Contributor

Hi,,

I'm not quite sure I'm understanding.  If I'm trying to change the structure of a request (due to an update in the schema), how would I use a property to accomplish this?

 

Thanks,

Mike

mwalter
Occasional Contributor

Hi,

Currently, we don't have any of this test using Groovy.  I understand what most examples are doing, but I'm not exactly fluid in Groovy yet (I've done a couple of simple XML-based events).  The JsonBuilder sounds like it might be a possible solution but I'm not familiar with how it works or exactly how it would be implemented.  Is there any good doc on that or a site you know of with good explanation?

 

Thanks,

Mike

PaulMS
Super Contributor

I assumed that you wanted to change some data/values within the request, not necessarily the structure. 

 

Are these examples similar to your scenario?

http://stackoverflow.com/questions/31160715/how-could-i-set-value-of-json-object-as-a-request-in-soa...

http://stackoverflow.com/questions/25491441/pass-properties-as-json-in-soapui

cancel
Showing results for 
Search instead for 
Did you mean: