# How to use RawFileBody to post a json file

**URL:** <https://community.gatling.io/t/how-to-use-rawfilebody-to-post-a-json-file/3240>\
**Category:** Gatling (Open-Source)\
**Created:** [September 6, 2016, 5:54pm UTC](https://community.gatling.io/t/how-to-use-rawfilebody-to-post-a-json-file/3240 "2016-09-06T17:54:38Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zhu\_Hui\_Wang](https://avatars.discourse-cdn.com/v4/letter/z/65b543/32.png) [@Zhu\_Hui\_Wang](https://community.gatling.io/u/Zhu_Hui_Wang)\
**Post date:** [September 6, 2016, 5:54pm UTC](https://community.gatling.io/t/how-to-use-rawfilebody-to-post-a-json-file/3240/1 "2016-09-06T17:54:38Z")

</div>

Hello,

I am trying to write a load test to do a POST to an endpoint using a raw body.

I have a json file which I would like to use to test the POST call. It’s something like

{  
“x\_content”: “12”,  
“y\_object”:{  
“z\_content”: “34”,  
“a\_content”: [  
[  
[  
1.22,  
3.44  
]

]  
]  
}  
}

and it’s currently saved in the /data directory. Upon running the test it can’t seem to find my test file and after reading the Gatling document, it says all files should be uploaded in the /bodies directory.Do I need to create this directory manually? If so, what should the classpath be?

Here is an example of my test:

.exec(  
http(“post data”)  
.post("/test\_data")  
.body(RawFileBody(“my\_request.json”))  
.asJSON  
.check(status.is(200))  
)

---

<div class="post-metadata">

**Author:** ![CyberNinja](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CyberNinja](https://community.gatling.io/u/CyberNinja)\
**Post date:** [September 6, 2016, 11:56pm UTC](https://community.gatling.io/t/how-to-use-rawfilebody-to-post-a-json-file/3240/2 "2016-09-06T23:56:05Z")

</div>

from conf/gatling.conf  
`

directory {  
#data = user-files/data # Folder where user’s data (e.g. files used by Feeders) is located  
#bodies = user-files/bodies # Folder where bodies are located  
#simulations = user-files/simulations # Folder where the bundle’s simulations are located

`

so keep your json file in user-files/bodies folder.

---

<div class="post-metadata">

**Author:** ![Zhu\_Hui\_Wang](https://avatars.discourse-cdn.com/v4/letter/z/65b543/32.png) [@Zhu\_Hui\_Wang](https://community.gatling.io/u/Zhu_Hui_Wang)\
**Post date:** [September 7, 2016, 12:57pm UTC](https://community.gatling.io/t/how-to-use-rawfilebody-to-post-a-json-file/3240/3 "2016-09-07T12:57:18Z")

</div>

Ok so I have manually created a bodies folder under resources as my data folder is in resources as well but when i run the test i still get a 'file my\_request.json doesn’t exist ’ error.

---

<div class="post-metadata">

**Author:** ![Nikolay\_Degkin](https://avatars.discourse-cdn.com/v4/letter/n/a6a055/32.png) [@Nikolay\_Degkin](https://community.gatling.io/u/Nikolay_Degkin)\
**Post date:** [September 9, 2016, 4:00pm UTC](https://community.gatling.io/t/how-to-use-rawfilebody-to-post-a-json-file/3240/4 "2016-09-09T16:00:25Z")

</div>

You can try following:

`.exec(http("Set") .post("/") .body(StringBody("""{"location" : {"address" : {"country" : "USA",},}}""")).asJSON`

---

<div class="post-metadata">

**Author:** ![CyberNinja](https://avatars.discourse-cdn.com/v4/letter/c/f6c823/32.png) [@CyberNinja](https://community.gatling.io/u/CyberNinja)\
**Post date:** [September 9, 2016, 11:32pm UTC](https://community.gatling.io/t/how-to-use-rawfilebody-to-post-a-json-file/3240/5 "2016-09-09T23:32:41Z")

</div>

the bodies directory has to be in user-files folder. If you don’t want that, just change gatling.conf to point the bodies directory to the directory that contains your jsons.
