Forum Discussion

mwalter's avatar
mwalter
Occasional Contributor
8 years ago

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

  • New2API's avatar
    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!

     

          

     

     

    • mwalter's avatar
      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