Here's a sample JSON request: Sample1 comes with an attribute Type and it's empty. Is it possible if the attribute is empty. Can this be removed like the output on sample2. I tried to use the remove...
import groovy.json.*
// Deserialize JSON into generic map
def obj = new JsonSlurper().parseText(Sample1)
// Remove Type
obj.getAt("Transfer").getAt("Instruct").getAt("Account").remove("Type")
// Serialize back to Json
String json = new JsonBuilder(obj).toString()
This does assume that the structure of these objects will always be the same. If that is not the case, you would need to iterate the map.
Thanks for the input. When you say Sample1 do you mean an input file or a REST (POST message ) like something shown below. As I do need to pull out data from the Excel data sheet.
Thanks for replying back. I have been trying to think how this would work for me. I am a newbie on rest. I couldn't figure out how to do the following steps.
1. I have uploaded JSON.jpg. I don't want to define the whole string on the script. I know you have said that you can pull that out from anywhere. how do I slurp out from the JSON (REST) message request( i have uploaded Json.jpg file).
2. Now, you mentioned that serialize back to json. Once that is done. How do I send it to testRunner to use serialize object and send to testRunner. I normally do this statement: testRunner.runTestStepByName("JSON");