JSON Data Interchange Format (Photo Credit: Tima Miroshnichenko)

The JSON Format For Open Data Interchange

Vincent T.
0xCODE

--

JSON (Javascript Object Notation) provides an open standard for stateless data interchange. The format is used by web applications to exchange data using RESTful APIs. The format uses human readable text which can be parsed and processed using serialization techniques.

Although it was derived from Javascript (JS), the format is language agnostic which makes it independent of the development environment used. It is open to any type of system that supports the format, as opposed to a proprietary system which is specific to a development environment.

The JSON file format is:

 .json

A file with a .json extension denotes a JSON format which can be used to exchange data between a server and client over public networks like the Internet.

Data Structure Format

JSON does not have a fixed syntax when it comes to presenting the data. It does have a structure that must be followed in order to be processed. The data is serialized attribute-value pairs which can be parsed and stored into another system (e.g. database).

Here is a simple example of a JSON format that shares information about a person. Let’s assume that this is data that a user provides to a merchant during an online transaction.

{
"firstName": "John",
"lastName": "Smith",
"DOB": {
"month":
"November",
"day":
1,
"year":
1984
},

"address": {
"streetAddress": "1630 Fuller Avenue",
"city": "Los Angeles",
"state": "CA",
"postalCode": "90046"
},
"email": "jsmith@mydomain.com
"phone": "301-555-5555"
}

Another example is when it comes to storing information, similar to an actual database. In this case let us create a collection of a class. We will use books and then specify titles under it.

{
"book": [

{
"id":"01",
"title": "DIY Car Repair",
"author": "Johnny Good"
},

{
"id":"02",
"title": "Dog Walking",
"author": "Jane Smiley"
}
]
}

The format of the second example takes a class called “book”, and under that are two types of books. The books are identified by an “id”, “title” and “author”. These are key value pairs that are contained inside an array-like data structure. With the data in JSON format, developers can parse it into more detailed information and presented in human readable format.

The following data types are supported in JSON:

Number — Double-precision floating-point format

String — Double-quoted Unicode, backslash escaping

Boolean — True or False

Array — Ordered sequence of values

Value —A string, number, True or False, null etc.

Object — Unordered collection of key/value pairs (key: value)

Whitespace — Used between any pair of tokens

null — Empty, no value

JSON In Web Applications

We can create objects in Javascript using JSON. The following example shows how to create variable objects that use a JSON format in a web page.

<html><head><title>JSON Objects In Javascript</title>    <script language = "javascript" >       var jsObject = { "model" : "F12BERLINETTA", "make": "Ferrari", "year"  : 2012 };       var jsObject2 = { "model" : "Model S", "make": "Tesla", "year"  : 2022 };    document.write("<h1>Autoshow Car Lineup</h1>");
document.write("<br>");
document.write("<h3>Make = "+jsObject.make+"</h3>");
document.write("<h3>Model = "+jsObject.model+"</h3>");
document.write("<h3>Year = "+jsObject.year+"</h3>");
document.write("+++++++++++++++++++++"); document.write("<h3>Make = "+jsObject2.make+"</h3>");
document.write("<h3>Model = "+jsObject2.model+"</h3>");
document.write("<h3>Year = "+jsObject2.year+"</h3>");
</script></head> <body> </body></html>

This produces the following output.

The two objects are variables in the DOM environment. We have jsObject and jsObject2, that represent the two cars (Ferrari and Tesla).

REST API

JSON can be sent as request payload in REST API calls. The standard way to transfer data is using a JSON format file or message. This is the technique when testing function calls using tools like Postman.

Let’s say you have some data in a message as payload to post to a web service.

"payload":{   "legalName":"Awesome Brands LLC",   "businessName":"AB",   "brands":["Gucci", "Yves St. Laurent", "Louis Vuitton"],   "type":"Manufacturer",   "corporateWebsite":"www.awesome.com",   "taxId":"0000001234",   "taxIdCountry":"USA",   "address":{     "addressLine1":"400 Potter Street",     "addressLine2":"",     "city":"Los Angeles",     "country":"USA",     "state":"CA",     "zipCode":"90020"
}
}

When sending this, the POST method is used. If it is successful, it will return a 200 OK message. Otherwise the post could fail and return another type of message.

Synopsis

JSON is a light-weight standard designed to simplify data interchange. This allows developers to communicate with other applications using an API to seamlessly exchange data. Without a standard format like JSON, exchanging data from non-compatible systems would require much more work for developers to parse the data into useful information.

--

--

Vincent T.
0xCODE

Blockchain, AI, DevOps, Cybersecurity, Software Development, Engineering, Photography, Technology