How to Convert JSON Object In Flutter

Credit: Pexels.com | RealToughCandy.com

You might already know how to install a package and receive JSON requests from my last blog, but that JSON response isn’t a map object where you can utilize it for your project use. That is why today I am going to introduce a dart function that can decode the JSON object into something useful.

The response isn’t a map, it is a JSON Object. When we try to call a specific key shown in the image below, it won’t work.

JSON Decode

The solution to our problem is the jsonDecode function. The usage of this was first you must import it by import 'dart:convert';

Now we will use it by passing our response body to the jsonDecode function parameters and then we can assign that into a Map that will be useful to call a specific property using its key.

We can now print the data in a map object and then call its properties using keys.

Conclusion

We can now utilize the JSON Object that was return to us by the http get function on my last blog post using the jsonDecode function which gave us a method to address a specific key value. Thank you once again for reading.

Leave a Comment

Your email address will not be published. Required fields are marked *