# Use a JSON parameter on body XML field

**URL:** <https://community.postman.com/t/use-a-json-parameter-on-body-xml-field/16999>\
**Category:** Help Hub\
**Tags:** tests, variables, json\
**Created:** [October 22, 2020, 12:11pm UTC](https://community.postman.com/t/use-a-json-parameter-on-body-xml-field/16999 "2020-10-22T12:11:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricardorio28](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@ricardorio28](https://community.postman.com/u/ricardorio28)\
**Post date:** [October 22, 2020, 12:11pm UTC](https://community.postman.com/t/use-a-json-parameter-on-body-xml-field/16999/1 "2020-10-22T12:11:05Z")

</div>

Hi,

I am trying to test a SOAP webserver with Postman and I was able to, but now I need to automate it.

**Pre-Request Script**  
On pre-request script, I create a JSON structure to be possible to create more than one test at the same time and then I create a copy of that structure and update the values what I need and put that in a environments variables

 ![Captura de ecrã 2020-10-22, às 12.59.17](https://us1.discourse-cdn.com/getpostman/original/3X/d/b/dba378b5d8005e82a4c42443a6294ddce4d10d45.png)

**Test**  
On Test, I pick the global variables and check if the “Tests” array in at the end, if is, the test will finish, if not will call the same request

 ![Captura de ecrã 2020-10-22, às 12.59.51](https://us1.discourse-cdn.com/getpostman/original/3X/1/2/12bc21661bf3964d7ee0f420cfe1f684725c556e.png)

**Body**  
On Body, I have a SOAP structure and I am not getting the value of “body.name” or “body.description”

 ![Captura de ecrã 2020-10-22, às 13.12.35](https://us1.discourse-cdn.com/getpostman/original/3X/b/4/b4cf13d196cec2f9e87d2c82f4062e6497acf650.png)

Someone can tell me what I need to do to fix the body issue, please?

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [October 23, 2020, 2:14am UTC](https://community.postman.com/t/use-a-json-parameter-on-body-xml-field/16999/2 "2020-10-23T02:14:05Z")

</div>

Hi @ricardorio28,

Very nice setup! From what I see, I don’t think you can do what you are trying to achieve.

First, it looks like your proper syntax would be {{body.name}} or {{body.description}}. However, in the case when using for your XML body for your POST request, you can’t reference variable values in that same way. In a Pre-Request Script or Tests section, you can, but not here.

The variable reference pulls out strings, and not JSON objects, when being used in the raw request body.

I would suggest creating a “bodyName” variable, and a “bodyDescription” variable, which should then resolve this issue.

I hope this helps!

---

<div class="post-metadata">

**Author:** ![ricardorio28](https://avatars.discourse-cdn.com/v4/letter/r/90db22/32.png) [@ricardorio28](https://community.postman.com/u/ricardorio28)\
**Post date:** [October 23, 2020, 5:25am UTC](https://community.postman.com/t/use-a-json-parameter-on-body-xml-field/16999/3 "2020-10-23T05:25:55Z")

</div>

Thanks 😉

I will need to do that but I will try something more dynamic…I am thinking to create a function on global variables to create the environment variables for me…something like this…with this will be easier to send the values for the “postman body”

> (jsonObject) =\> {  
> for ( var parameter in jsonObject ){  
> pm.environment.set(parameter, jsonObject[parameter]);  
> }  
> }

---

<div class="post-metadata">

**Author:** ![odanylewycz](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/odanylewycz/32/3240_2.png) [@odanylewycz](https://community.postman.com/u/odanylewycz)\
**Post date:** [October 23, 2020, 11:03am UTC](https://community.postman.com/t/use-a-json-parameter-on-body-xml-field/16999/4 "2020-10-23T11:03:03Z")

</div>

Hi @ricardorio28,

I think thats a good idea and should suffice. You can even do value teardown if you’d like in the tests section. This I believe would solve your issue where you need dynamic values.

You would just need to parse the `jsonObject` in the pre-request script using `var jsonObject = JSON.parse(globalEnvJsonString)` and then you can reference it as a json object natively.

Additionally, from your current example, you shouldnt have to loop through your jsonObject, unless there was an array, to assign the variable you can just use the following:

`pm.environment .set(bodyName, jsonObject.body.name)`

But if you had an array of these objects, then I would look through them.

Of course the syntax depends on how you structure the json, but all in all, should be very doable.
