# How to read json file in custom action python file in rasa

**URL:** <https://forum.rasa.com/t/how-to-read-json-file-in-custom-action-python-file-in-rasa/44282>\
**Category:** Rasa Open Source\
**Created:** [June 4, 2021, 2:27pm UTC](https://forum.rasa.com/t/how-to-read-json-file-in-custom-action-python-file-in-rasa/44282 "2021-06-04T14:27:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![harika516](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.rasa.com/harika516/32/14879_2.png) [@harika516](https://forum.rasa.com/u/harika516)\
**Post date:** [June 4, 2021, 2:27pm UTC](https://forum.rasa.com/t/how-to-read-json-file-in-custom-action-python-file-in-rasa/44282/1 "2021-06-04T14:27:01Z")

</div>

Hi… I want to read the json file in custom action file to do the configuration.

class ActionReadFile(Action): def name(self): return “action\_Read\_File”

```
def run(self, dispatcher, tracker, domain):
    try:
        with open("config_mysql.json", "r") as jsonfile:
             config_data = json.load(jsonfile) # Reading the file
             print("Read successful")
             jsonfile.close()
             data=config_data["dev"]   

```

The folder structure:

opt/RasaBot/actions/action\_Read\_File.py opt/RasaBot/config\_mysql.json

But I am getting [Errno 2] No such file or directory: ‘opt/ChatBot/config\_mysql.json’

In command prompt : The current directory is opt/RasaBot

Could you help anyone How to overcome this issue

---

<div class="post-metadata">

**Author:** ![harloc](https://avatars.discourse-cdn.com/v4/letter/h/73ab20/32.png) [@harloc](https://forum.rasa.com/u/harloc)\
**Post date:** [June 7, 2021, 8:42am UTC](https://forum.rasa.com/t/how-to-read-json-file-in-custom-action-python-file-in-rasa/44282/2 "2021-06-07T08:42:53Z")

</div>

What confuses me ist that you open “config\_mysql.json”, but the error states ‘opt/ChatBot/config\_mysql.json’. If your current folder is “opt/RasaBot” then it should state that “config\_mysql.json” is not available without the mention of some path before the actual file name. I would check your setup again. Often it helps to use an absolute path the the file in your open statement.

Additionally, you do not have to use `jsonfile.close()`, because the `with open`-statenebt already closes the file at the end. Although, this should not the cause of the error, it makes your code more readable.
