Dr.M.UMADEVI
ASSISTANT PROFESSOR
DEPARTMENT OF CS
SACWC
CUMBUM
JSON
 JavaScript Object Notation (full form of JSON) is a standard file
format used to interchange data. The data objects are stored and
transmitted using key-value pairs and array data types. In simpler
terms, JSON data is (in some ways) the language of databases.
 JSON has syntactic similarity to JavaScript because JSON is based
on JavaScript object notation syntaxes. But JSON format is text
only, which makes it easy to read and use with any programming
language. This blog will introduce you to everything there is to
know of JSON.
JSON USED
 JSON data format is ubiquitous in web APIs, cloud computing,
NoSQL databases (like MongoDB), and increasingly also in
Machine Learning.
 More generic scenarios where JSON data format is used are:
 Data storage, configuration, and validation
 Data transfer between APIs, client, and server
 Restructuring input data from the user (JSON schema)
DATA STORAGE, CONFIGURATION, AND
VALIDATION
 You might be familiar with the package.json files in your node
(specifically NPM) projects.
 This is a configuration file for your project which holds important
metadata. Also, JSON files can be used to store tons of data that you
may need to use within your project itself.
 Think of it as an internal mini-database for text-only data. Refer to
the two photos below for the two cases I explained (respectively).
 JSON plays a very critical role in validation, as in via JWT (JSON
Web Token), which is a method of securely transmitting digital
information between two parties.
 Think of it like a digital signature that authorizes an app to proceed
with its operations further.
DATA TRANSFER BETWEEN APIS, CLIENT,
AND SERVER
 Data transfer often occurs in JSON format (which exists as a string)
as it does not burden the network in any way due to its low memory
demand.
 Though this string needs to be converted into a native JavaScript
object if you want to access the data (more on this later).
 This helps faster and efficient data transfer between these parties.
RESTRUCTURING INPUT DATA FROM THE
USER (JSON SCHEMA)
 JSON Schema is a standard format for declaring the structure of
JSON data.
 Validators exist to verify if a JSON document fits within schema’s
constraints, i.e. the values of properties (of a data object) are valid or
not.
 So a user’s input to a certain application is restructured to an
organized JSON data with the help of this schema.
WHY JSON?
 While handling data (in databases) data structuring is very crucial;
because it makes data querying more specific and easier.
 JSON is a minimal, readable format for this structured data. It is
extremely lightweight and thus is used in the interaction between
server and client (HTTP requests).
 JSON is an alternative to XML, the latter being more complex.
Using JSON, data can be managed and handled logically.
 The extension of a JSON file is .json .
JSON SYNTAXES AND DATA TYPES
 The rules of writing JSON data are homogeneous to JavaScript
Object Literals.
 All JSON data is written inside curly braces
 JSON data is represented as key-value pairs
 Key should always be enclosed in double quotes
 Always separate Key and value with a colon (:)
 Values should be written appropriately; for String double quotes
should be used while for Numbers, Boolean quotes should not be
used.
 To separate data commas (,) should be used
 For array square brackets and objects, curly braces should be used
 JSON utilizes objects or arrays (as shown in the above example) to
present its data. These data contain values (of keys) which can be of
the following formats -
 Number (integer or decimal)
 String (should be in double quotes)
 Boolean (i.e. true or false)
 Null
 Objects
 Arrays
 An object is a collection of key-value pairs defining a data set;
while an array is an ordered list of values. JSON objects can
contain multiple JSON arrays and vice-versa.
JSON array declaration
[
"Full stack track", "Backend track", "Fellowship program"
]
JSON object declaration
{
"id": 54d56a2c4,
"Name":"Crio.Do",
"Contact":"ping@criodo.com",
"careerPrograms": ["Crio Launch", "Crio Accelerate"]
}
WORKING OF JSON
 Now you may be wondering about the “complex” mechanism JSON
uses to transfer this data. Turns out, the process is not so complex.
Rather it uses a computing method called Serialization.
 Consider an application operating on a certain physical machine. If it
wants to send some data to another application within the same
machine or a different one it can transmit the data using some
suitable network protocol.
 Data cannot be sent as it is, i.e. as one large chunk of data that a low-
level machine can’t understand. For the two machines to understand
the data, it needs to be in the form of bits i.e. 0s and 1s.
 So in other words, data transfer should occur in the form of
bits/bytes. This is what Serialization does.
 Serialization is a mechanism that converts the state of a data object
into a string of bits called a byte stream (or byte string). And once
the other machine receives this byte stream it needs to "deserialize"
the byte stream back to its original data object state so that it can be
comfortably used further.
 This mechanism of serialization-deregulation ensures the persistence
of data objects across the various applications involved.
 JSON format encodes objects in a string. However, during data
transmission or storage in a file, the data has to be byte strings. This
isn't the usual format of complex objects.
 Serialization converts these complex objects into byte strings for
such use. This is the working mechanism of JSON.
JSON AND REST APIS
 An API (Application Programming Interface) is an application
dedicated to transferring data between multiple software applications
or even hardware software.
 But the issue is APIs aren’t readable or self-expressible. API data is
for machines to format and execute.
 Data in APIs are commonly transferred in the JSON format because
“It is easy for humans to read and write” and “It is easy for machines
to parse and generate.”
 Earlier it was a cumbersome task to manage and locate data of
different APIs of the same parent application.
 REST (Representational State Transfer) is a guiding principle for
how to use URLs and HTTP protocols to format your API.
PRACTICAL APPLICATIONS OF JSON
 Perhaps the most common one, JSON is used in NoSQL databases
i.e. non-relational databases.
 These document-based databases store data in the form of queries
that are converted from the accepted JSON documents.
 These databases accept any JSON-based documents due to the
flexible nature of JSON.
 These databases are commonly used in web APIs and other client-
server applications in general.
 A simple example of where JSON is most useful. Consider a
shopping website like Amazon or Flipkart.
 These websites are dynamic in nature and hard coding each product
into the database is just impossible.
Json

Json

  • 1.
  • 2.
    JSON  JavaScript ObjectNotation (full form of JSON) is a standard file format used to interchange data. The data objects are stored and transmitted using key-value pairs and array data types. In simpler terms, JSON data is (in some ways) the language of databases.  JSON has syntactic similarity to JavaScript because JSON is based on JavaScript object notation syntaxes. But JSON format is text only, which makes it easy to read and use with any programming language. This blog will introduce you to everything there is to know of JSON.
  • 3.
    JSON USED  JSONdata format is ubiquitous in web APIs, cloud computing, NoSQL databases (like MongoDB), and increasingly also in Machine Learning.  More generic scenarios where JSON data format is used are:  Data storage, configuration, and validation  Data transfer between APIs, client, and server  Restructuring input data from the user (JSON schema)
  • 4.
    DATA STORAGE, CONFIGURATION,AND VALIDATION  You might be familiar with the package.json files in your node (specifically NPM) projects.  This is a configuration file for your project which holds important metadata. Also, JSON files can be used to store tons of data that you may need to use within your project itself.  Think of it as an internal mini-database for text-only data. Refer to the two photos below for the two cases I explained (respectively).  JSON plays a very critical role in validation, as in via JWT (JSON Web Token), which is a method of securely transmitting digital information between two parties.  Think of it like a digital signature that authorizes an app to proceed with its operations further.
  • 5.
    DATA TRANSFER BETWEENAPIS, CLIENT, AND SERVER  Data transfer often occurs in JSON format (which exists as a string) as it does not burden the network in any way due to its low memory demand.  Though this string needs to be converted into a native JavaScript object if you want to access the data (more on this later).  This helps faster and efficient data transfer between these parties.
  • 6.
    RESTRUCTURING INPUT DATAFROM THE USER (JSON SCHEMA)  JSON Schema is a standard format for declaring the structure of JSON data.  Validators exist to verify if a JSON document fits within schema’s constraints, i.e. the values of properties (of a data object) are valid or not.  So a user’s input to a certain application is restructured to an organized JSON data with the help of this schema.
  • 7.
    WHY JSON?  Whilehandling data (in databases) data structuring is very crucial; because it makes data querying more specific and easier.  JSON is a minimal, readable format for this structured data. It is extremely lightweight and thus is used in the interaction between server and client (HTTP requests).  JSON is an alternative to XML, the latter being more complex. Using JSON, data can be managed and handled logically.  The extension of a JSON file is .json .
  • 8.
    JSON SYNTAXES ANDDATA TYPES  The rules of writing JSON data are homogeneous to JavaScript Object Literals.  All JSON data is written inside curly braces  JSON data is represented as key-value pairs  Key should always be enclosed in double quotes  Always separate Key and value with a colon (:)  Values should be written appropriately; for String double quotes should be used while for Numbers, Boolean quotes should not be used.  To separate data commas (,) should be used  For array square brackets and objects, curly braces should be used
  • 9.
     JSON utilizesobjects or arrays (as shown in the above example) to present its data. These data contain values (of keys) which can be of the following formats -  Number (integer or decimal)  String (should be in double quotes)  Boolean (i.e. true or false)  Null  Objects  Arrays  An object is a collection of key-value pairs defining a data set; while an array is an ordered list of values. JSON objects can contain multiple JSON arrays and vice-versa.
  • 10.
    JSON array declaration [ "Fullstack track", "Backend track", "Fellowship program" ] JSON object declaration { "id": 54d56a2c4, "Name":"Crio.Do", "Contact":"ping@criodo.com", "careerPrograms": ["Crio Launch", "Crio Accelerate"] }
  • 11.
    WORKING OF JSON Now you may be wondering about the “complex” mechanism JSON uses to transfer this data. Turns out, the process is not so complex. Rather it uses a computing method called Serialization.  Consider an application operating on a certain physical machine. If it wants to send some data to another application within the same machine or a different one it can transmit the data using some suitable network protocol.  Data cannot be sent as it is, i.e. as one large chunk of data that a low- level machine can’t understand. For the two machines to understand the data, it needs to be in the form of bits i.e. 0s and 1s.
  • 12.
     So inother words, data transfer should occur in the form of bits/bytes. This is what Serialization does.  Serialization is a mechanism that converts the state of a data object into a string of bits called a byte stream (or byte string). And once the other machine receives this byte stream it needs to "deserialize" the byte stream back to its original data object state so that it can be comfortably used further.  This mechanism of serialization-deregulation ensures the persistence of data objects across the various applications involved.  JSON format encodes objects in a string. However, during data transmission or storage in a file, the data has to be byte strings. This isn't the usual format of complex objects.  Serialization converts these complex objects into byte strings for such use. This is the working mechanism of JSON.
  • 13.
    JSON AND RESTAPIS  An API (Application Programming Interface) is an application dedicated to transferring data between multiple software applications or even hardware software.  But the issue is APIs aren’t readable or self-expressible. API data is for machines to format and execute.  Data in APIs are commonly transferred in the JSON format because “It is easy for humans to read and write” and “It is easy for machines to parse and generate.”  Earlier it was a cumbersome task to manage and locate data of different APIs of the same parent application.  REST (Representational State Transfer) is a guiding principle for how to use URLs and HTTP protocols to format your API.
  • 14.
    PRACTICAL APPLICATIONS OFJSON  Perhaps the most common one, JSON is used in NoSQL databases i.e. non-relational databases.  These document-based databases store data in the form of queries that are converted from the accepted JSON documents.  These databases accept any JSON-based documents due to the flexible nature of JSON.  These databases are commonly used in web APIs and other client- server applications in general.  A simple example of where JSON is most useful. Consider a shopping website like Amazon or Flipkart.  These websites are dynamic in nature and hard coding each product into the database is just impossible.