How to read a JSON file from the assets folder using Kotlin

Oscar de la Hera Gomez
Two flowers that represent Kotlin and Android Studio. Beneath them sits the text "Read JSON."

A step by step guide on reading a JSON file from the assets folder of an Android Studio project and converting it to a string in Kotlin.

Step One: Create the JSON

A screenshot of the pop up that appears in Android Studio when you create a new file. Highlighted is the area where you enter the name. We have written sample.json. Write the name of the file that you wish and press enter to create the file.

Follow the tutorial below to create a JSON that can be read by an Android app.

Step Two: Create Read JSON Utility

A screenshot of Android Studio showing the ReadJSON utility.

In your project, create a new file called ReadJSONFromAssets.kt and input the code below.

We suggest you place this in a utilities folder, but you can also opt to not create a file and place the function below wherever you wish in your project.

Step Three: Read the JSON

A screenshot of Androids Studio showing the ReadJSON utility being called and it successfully finding a file. This success is shown on the LogCat logs.

Call ReadJSONFromAssets by passing an activity or composable's context and the name of the JSON file.

Looking to convert the JSON into usable data?

To learn how to convert a JSON into usable data in Kotlin and Android Studio follow the tutorial below.

Any Questions?

We are actively looking for feedback on how to improve this resource. Please send us a note to inquiries@delasign.com with any thoughts or feedback you may have.
delasign logo

Book a Free Consultation.

An icon of an email.

Click here to email us.

Fill in the details below to book a free consultation or to let us know about something else. Whatever it is, we are here to help.

How can we help you ?

Contact Details