# How to create a new Body json field with combining all active keys in x-www-form-urlencoded

**URL:** <https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390>\
**Category:** Help Hub\
**Tags:** pre-request-script\
**Created:** [June 20, 2022, 8:09pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390 "2022-06-20T20:09:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [June 20, 2022, 8:09pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/1 "2022-06-20T20:09:21Z")

</div>

Hi guys,

There is a request with active x-www-form-urlencoded Body key. The key value is in JSON format. There are also not enabled keys that can be used to send different Body values.

Due to large Body size it would be more convenient if I could enter each JSON key separately in x-www-form-urlencoded and process in Pre-request Script by combining all active keys to a new Body JSON field before sending the request.

Is it possible?

Thanks

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 21, 2022, 3:34pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/2 "2022-06-21T15:34:59Z")

</div>

Hi @osiuser

Not sure I follow exactly what your are trying to do, but could you not just add the list of values you need to the **body** \> **x-www-form-urlencoded** tab?

![image](https://us1.discourse-cdn.com/getpostman/original/2X/c/c924501062083f96fe0ec60b6fbc8b1d415fe829.png)

---

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [June 21, 2022, 6:24pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/3 "2022-06-21T18:24:12Z")

</div>

To send a request I have to add “Body” key on that screen. The value of this key is in JSON format and can be large enough due to many elements included.

What I want to do is to avoid using the “Body” key and rather to use separate small keys. But because the “Body” key in the request Body is mandatory for the call I need somehow to process all Active keys (because some can be inactive) and combine from them the required “Body” field before sending the request. And do it behind the scene like Pre-request Script does.

For example,

 ![image](https://us1.discourse-cdn.com/getpostman/original/2X/3/3828a55d1765c78ccef284b7962963c20b826b5e.png)

sends this in the Request Body

![image](https://us1.discourse-cdn.com/getpostman/original/2X/9/964fa33831ba8251e5a84d48bb50a46a4a9ba353.png)

And I want it to be sent as

![image](https://us1.discourse-cdn.com/getpostman/original/2X/7/73f16d5ddb6324dbdfb39b76dd887bb984b6a352.png)

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 21, 2022, 6:57pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/4 "2022-06-21T18:57:52Z")

</div>

Hmm, ok …

So if you have the JSON for the ‘body’ Key … could you not stringify that JSON in the pre-req script and then feed it in as a variable?

Similar to what is described in this thread?

> [@JSON Stringify request body using raw](https://community.postman.com/t/json-stringify-request-body-using-raw/5526):
>
> Hello, We’re using API Gateway and the request body needs to be stringified before sending. Right now, I the request body with a json under “raw” and the content-type of application/json. I’ve tried using: var body = { name: 'Test' }; pm.environment.set('req\_body', JSON.stringify(body)); Then passing in {{req\_body}}, but it’s coming in as the whole stringified object as a key with an empty value. Any ideas in this particular scenario how to get this to work in Postman? Thank you

---

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [June 22, 2022, 6:00pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/5 "2022-06-22T18:00:41Z")

</div>

Sorry, I don’t understand what you suggested. The article you referenced uses an Environmental variable in Raw body. But I use x-www-form-urlencoded Body keys.

---

<div class="post-metadata">

**Author:** ![w4dd325](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/w4dd325/32/12436_2.png) [@w4dd325](https://community.postman.com/u/w4dd325)\
**Post date:** [June 23, 2022, 8:53am UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/6 "2022-06-23T08:53:23Z")

</div>

If you know what the “key”:“value” pairs are, could you build a list of variables that hold these values, then build the JSON inside the pre-req, url-econde the string and then feed that into your script. It means you could pick the values you want to use from your pre-defined list.

Unless I have misunderstood what you are trying to achieve, in which case could you provide a bit more information?

---

<div class="post-metadata">

**Author:** ![osiuser](https://avatars.discourse-cdn.com/v4/letter/o/dec6dc/32.png) [@osiuser](https://community.postman.com/u/osiuser)\
**Post date:** [July 12, 2022, 1:02pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/7 "2022-07-12T13:02:21Z")

</div>

My understanding Postman takes all enabled keys to created the request Body and send the request.

What I need is:

- Combine all enabled keys to a new key “Body”
- Don’t remove the existing keys or adding a new keys in UI
- I want Postman to send the request by sending ONLY this new key “Body”

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/system/32/29796_2.png) [@system](https://community.postman.com/u/system)\
**Post date:** [December 12, 2024, 12:54pm UTC](https://community.postman.com/t/how-to-create-a-new-body-json-field-with-combining-all-active-keys-in-x-www-form-urlencoded/36390/8 "2024-12-12T12:54:13Z")

</div>

Closed on December 12, 2024, 12:54pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
