w3resource logo


json introduction

JSON Tutorial

rating has average rating 8 out of 10. Total 205 users rated.

<<PreviousNext>>

Introduction to JSON

This page introduces you to JSON - JavaScript Object Notation. We have discussed definition, history, usage and Comparison with XML of JSON in this page.

What is JSON

JSON is a lightweight text-based open standard data-interchange format.

You can read and write JSON easily.

JSON is derived from a subset of JavaScript programming language (Standard ECMA-262 3rd Edition—December 1999).

It is entirely language independent and can be used with most of the modern programming languages.

JSON files are saved with .json extension.

Internet media type of JSON is "application/json".

JSON LOGO

A simple example of JSON

{
"Students": [
{ "Name": "Amit Goenka",
"Major": "Physics"
},
{
"Name": "Smita Pallod",
"Major": "Chemistry"
},
{
"Name": "Rajeev Sen",
"Major": "Mathematics"
}
]
}

The above example shows information about three students - their name and major subjects are stored using JSON.

Though you need to read and understand JSON structures to understand the concept of JSON better, the following image may help you to understand the concept of JSON a little better.

JSON introduction tutorial, w3resource

History of JSON

The name behind popularizing the JSON is Douglas Crockford. He used JSON is his company State Software around 2001.

In 2005, Yahoo started using JSON in it's web services.

In later 2006, Google started offering JSON in it's Gdata web protocol.

Today, JSON is one of the most widely used data-interchange format in web, and supported by most of the Web APIs (like twitter api) to fetch public data and creating applications out of them.

Usage

Various Web Services and APIs use JSON format to provide public data. Using the associated Service / API, you can fetch that data and use it to create applications.

For example, if you click this link, you would get user information about 'w3resource' in twitter and last two tweets of the user.

If you look the available data closely you will see meaningful information in a very structured way. But for now, since we yet to discuss JSON structure, you can see the user information in a much more presentable way in the following pictorial presentation (output).

twitter example

JSON format (or a close derivative of that) is used by various NoSQL databases to store data. For example MongoDb, CoucheDB uses JSON format to store data.

This is a simple document (as record in SQL) stored in MongoDB. MongoDB uses BSON (a derivative of JSON) format to store data.

FirstName="Arun", Address="St. Xavier's Road", Spouse=[{Name:"Kiran"}], Children=[{Name:"Rihit", Age:8}].
FirstName="Sameer",Address="8 Gandhi Road".

Comparison with XML

Since both JSON and XML are mean to be a data interchange format, there is always a comparison between JSON and XML.

The similarity between them lies in the points that, both of them are plain text, human readable and can be used with most of the modern programming languages.

But unlike XML, JSON supports data structures (name/value pairs and ordered list of values) which are universal in nature and supported by most of the modern programming languages in some form or other. Which makes JSON more comprehensible, easy to get started with (because you already know the format if you familiar with one or more modern programming languages) and thus easy to use.

Experiences of developers say that JSON is faster that XML.

XML is redundant in nature. Unlike JSON.

What you will learn in w3resource JSON tutorial

Structure and datatypes of JSON.

Working with JSON and PHP.

Working with JSON and JavaScript.

After reading this tutorial, you will gain knowledge to use JSON in practice..

photo credit: superfluity via photopin cc

<<PreviousNext>>