# How can I Validate Request Body Key and Value parameters that is in Form-data format

**URL:** <https://community.postman.com/t/how-can-i-validate-request-body-key-and-value-parameters-that-is-in-form-data-format/33075>\
**Category:** Help Hub\
**Tags:** tests, automation, json\
**Created:** [March 1, 2022, 7:38pm UTC](https://community.postman.com/t/how-can-i-validate-request-body-key-and-value-parameters-that-is-in-form-data-format/33075 "2022-03-01T19:38:03Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![sahuvikramp](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sahuvikramp/32/10828_2.png) [@sahuvikramp](https://community.postman.com/u/sahuvikramp)\
**Post date:** [March 3, 2022, 4:32pm UTC](https://community.postman.com/t/how-can-i-validate-request-body-key-and-value-parameters-that-is-in-form-data-format/33075/30 "2022-03-03T16:32:44Z")

</div>

I would really appreciate, if you can go through Postman’s learning center and check about writing [test script](https://learning.postman.com/docs/writing-scripts/test-scripts/).

Now since our data is in variable map and mapValue, there is no point in passing **`data.form.body`** 😅

The code will look something like this

```javascript
var data = pm.request.body
var myReq = data.formdata

var map = myReq.reduce((r, i) => ((r[i.key] = r[i.key] || []).push(i), r), {});
var mapValue = myReq.reduce((r, i) => ((r[i.value] = r[i.value] || []).push(i), r), {});

pm.test("Request body to have form Data key", function () {
    pm.expect(mapValue.client_credentials[0].value).to.be.a("string").and.is.not.null.and.to.not.be.undefined.and.is.not.empty
});

pm.test("Request body to have form Data value", function () {
    pm.expect(mapValue.default[0].value).to.be.a("string").and.is.not.null
});

```

As I said, it will be great help if you can research a bit more (solutions are all around) 😛 😃

Cheers 🪄

---

<div class="post-metadata">

**Author:** ![farhanhasanali](https://avatars.discourse-cdn.com/v4/letter/f/b3f665/32.png) [@farhanhasanali](https://community.postman.com/u/farhanhasanali)\
**Post date:** [March 3, 2022, 4:47pm UTC](https://community.postman.com/t/how-can-i-validate-request-body-key-and-value-parameters-that-is-in-form-data-format/33075/31 "2022-03-03T16:47:20Z")

</div>

> [@sahuvikramp](#):
>
> ```auto
> var data = pm.request.body
> var myReq = data.formdata
> 
> var map = myReq.reduce((r, i) => ((r[i.key] = r[i.key] || []).push(i), r), {});
> var mapValue = myReq.reduce((r, i) => ((r[i.value] = r[i.value] || []).push(i), r), {});
> 
> pm.test("Request body to have form Data key", function () {
> pm.expect(mapValue.client_credentials[0].value).to.be.a("string").and.is.not.null.and.to.not.be.undefined.and.is.not.empty
> });
> 
> pm.test("Request body to have form Data value", function () {
> pm.expect(mapValue.default[0].value).to.be.a("string").and.is.not.null
> });
> 
> ```

Thank you so much… I went through so may threads and tried but was really struggling.

---

<div class="post-metadata">

**Author:** ![sahuvikramp](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/sahuvikramp/32/10828_2.png) [@sahuvikramp](https://community.postman.com/u/sahuvikramp)\
**Post date:** [March 4, 2022, 1:44pm UTC](https://community.postman.com/t/how-can-i-validate-request-body-key-and-value-parameters-that-is-in-form-data-format/33075/32 "2022-03-04T13:44:57Z")

</div>

No worries 😁 I hope this worked for you.

[Previous page](https://community.postman.com/t/how-can-i-validate-request-body-key-and-value-parameters-that-is-in-form-data-format/33075.md?page=1)
