Sitemap
kanav bahri

kanav bahri

JSON Compact Overview

2 min readFeb 14, 2021

--

Press enter or click to view image in full size
Photo by Maxwell Nelson on Unsplash

JavaScript Object Notation, commonly known as 'JSON', is heavily leveraged as a data-interchange format. JSON is a subset of the JavaScript Programming language

JSON is a lightweight text format that is independent of any programming Languages thus making it an ideal option for data-interchange in today's Business world.

JSON Usage

  • Transfers data between a server and various web applications.
  • Performs asynchronous data calls without requiring a page refresh. This is widely used for asynchronous browser/server communicatio.
  • APIs and web services use JSON to transfer real-time sensitive data.
  • Compiles user data for local storage.
  • JSON is now being supported by almost all Programming languages.
  • JSON supports for sending, reading, and receiving texts available in all the real-world business.

JSON Syntax Rules

JSON syntax is basically considered as a subset of JavaScript syntax; it includes the following

  • Keys must necessarily be strings, written with double quotes. Example: "Value"
  • Data can be a Name/value pairs that consist of a field name inside double quotes, followed by a colon, and then by a value inside double quotes Example:"Value":"12345"
  • Data must be separated by Commas ‘,’. Example: "Katsa", "Aelin"
  • Curly brackets {} to hold objects Example: { "Value":"12345" }
  • Square brackets [] hold arrays Example: {"Animals":[ "Tiger", "Leopard ", "Lion" ]}

Valid Data Types

In JSON, values must be one of the following data types:

  • a string
  • a number
  • an object (JSON object)
  • an array
  • a boolean
  • null

JSON values cannot be one of the following data types:

  • a function
  • a date
  • undefined

JSON.parse()

When receiving data from a web server, the data is always a string. Parse the data with JSON.parse()

Get kanav bahri’s stories in your inbox

Join Medium for free to get updates from this writer.

Example
‘{ “name”:”Aelin”, “age”:17, “city”:”Terrassen”}’
var obj = JSON.parse(‘{ “name”:”Aelin”, “age”:17, “city”:”Terrassen”}’);

By this you can access name or other properties via obj.name…

JSON.stringify()

When sending data to a web server, the data has to be a string. Convert a JavaScript object into a string with JSON.stringify().

var obj = { name: “Rowan”, age: 30, city: “NA” };
var myJSON = JSON.stringify(obj);

Result: {“name”:”Rowan”,”age”:30,”city”:”NA”}

Ref: https://www.json.org/json-en.html
https://www.w3schools.com/js/js_json_intro.asp

Press enter or click to view image in full size
Photo by Kelly Sikkema on Unsplash

--

--