How to Decode JSON In Flutter

How to Decode JSON In Flutter?

JSON is short for JavaScript Object Notation and is a way to store information in an organized, easy-to-access manner. Generally, the entire communication between the app and the server is through JSON. So in this article, We will learn about How to Decode JSON In Flutter?

What is JSON?

JSON is often used when data is sent from a server to a web page.  JSON is a lightweight format for storing and transporting data.

How to Decode JSON In Flutter?

To Decode JSON follow the steps below:




In Dart 2 all screaming-case constants were changed to lower-camel-case.

Ensure to

import 'dart:convert';

Inline example

String rawJson = '{"name":"Mary","age":30}';

Map<String, dynamic> map = jsonDecode(rawJson); // import 'dart:convert';

String name = map['name'];
int age = map['age'];

Person person = Person(name, age);

Note: When I was doing this in VS Code for server-side Dart I had to specify the type:

Map<String, dynamic> map = jsonDecode(rawJson) as Map<String, dynamic>;

Model class example

The model class includes map conversion logic:

class Person {
  String? name;
  int? age;
  Person(, this.age);

  //from json
  factory Person.fromJson(Map json) {
    return Person(

  //to json
  Map toJson() {
    return {
      'name': name,
      'age': age,

And the JSON conversion is done like this:

String rawJson = '{"name":"Mary","age":30}';
Map<String, dynamic> map = jsonDecode(rawJson);
Person person = Person.fromJson(map);

Simply user need to import like a below

import 'dart:convert';
Decode : JsonDecoder().convert("$response");
Encode : JsonEncoder().convert(object)


In this article, we have been through How to Decode JSON In Flutter?

Keep Learning !!! Keep Fluttering !!!

Still, Need a Support for Flutter Development? is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

Nirali Patel

Written by Nirali Patel

Nirali Patel is a dedicated Flutter developer with over two years of experience, specializing in creating seamless mobile applications using Dart. With a passion for crafting user-centric solutions, Nirali combines technical proficiency with innovative thinking to push the boundaries of mobile app development.

ready to get started?

Fill out the form below and we will be in touch soon!

"*" indicates required fields

✓ Valid number ✕ Invalid number
our share of the limelight

as seen on