How to use JSON Data in Flutter? (Class 23)

How to use JSON Data in Flutter?

How to use JSON Data in Flutter?

It is so important for a Mobile App Developer to know how to use JSON data in Flutter. Why? because a mobile app developer needs to work on pubspec.yaml, plugins, and packages in Flutter. So today we are going to learn JSON structure. Let’s start

 

What is JSON

JSON is a structure rather than a programming language. It is a short form of JavaScript Object Notation. It is a Serialization Language. We use JSON for Data Transmission means data sending and receiving which is done between the Client and server.

 

Why we use JSON

It is an independent concept that exists in all technologies like web apps, mobile apps, desktop apps, etc. It is a compatible structure for data transmission.

 

How JSON works

We send gifts to our loved ones living in the country or abroad. For example, we intend to send them a precious watch. Now we will send it via courier. When we take it to them they will wrap it and send it to the destination. Our recipient will receive an open wrapping. Now, here the wrapping is to safely transmit the gift. Similarly, JSON works and transmits data between client and server.

JSON coding and decoding

From where the data is being sent in JSON is called sender end. This process can be named as covering, encoding, serialization, or conversion in JSON. The person responsible for sending the data is a Backend Developer.

Now when the data is received the process is called unpacking, decoding, deserialization, or conversion. Data receiving is the responsibility of the front-end developer. The backend & frontend Communication is done through JSON.

 

Alternative to JSON

It is important to remember that JSON structure is preferred but XAML and XML can also be used for the same purpose. The reason behind the preference for JSON is reliability and fast data transmission.

 

What is the structure of JSON?

Now we will discuss the all-important JSON structure. There are two things in JSON structure:

  1. JSON Array
  2. JSON Object

JSON Array

We represent JSON Array through square brackets [ ]. The data in JSON format is in plain or linear format. Data can be of any type like String, integer, etc. If we closely look at it, it is almost similar to a list. Let’s see its example:

 [

“Ali”,

45,

3.45,

false

]

Note: It is to remember that there would be no comma after the last value. We can say that we imported our data in JSON in the above example

.

JSON OBJECT

We represent JSON Object through curly braces { }. It is the same concept as Map. In JSON objects, we put data in the form of key/ value pairs. It is like data importing and its keys are in small letters, in String form, descriptive with any type of value. For example:

{

“name”:”Ali”,

“roll_no”:45,

“gpa”:3.45,

“ic_check: false”

}

Task: Try to make JSON array & object canin Dart Pad.

 

ROBINA KOUSAR
Content Writer
**************************
You can get all Mobile App Development Classes link from here:-

Related Posts

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.