What is JSON and Understanding JSON syntax with simple example

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages.

JSON is built on two structures

  • A collection of name/value pairs.
  • An ordered list of values.

Object is an unordered set of name/value pairs. An object begins with { (left brace) and ends with } (right brace). Each name is followed by : (colon) and the name/value pairs are separated by , (comma).

Example Object – a container of key-value pairs, e.g : { “foo”:”bar”, “x”:0.3 }

An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma).

Example Array – a sequence of values, e.g.: [ 1, 2, 3 ]

String is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes. A character is represented as a single character string. A string is very much like a C or Java string.

Example String – a quoted sequence of chars, e.g.: “foo”

A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.

Example value – a number e.g 78, a boolean (true, false) or null

Let’s consider a JSON string:

{
	"user": "johndoe",
	"admin": false,
	"uid": 1000,
	"groups": ["users", "wheel", "audio", "video"]
}

It holds the following tokens:

Object:

{
“user”: “johndoe”,
“admin”: false,
“uid”: 1000,
“groups”: [“users”, “wheel”, “audio”, “video”]
}

Strings: “user”: “johndoe” (keys and some values)

Related :   How to Remove a Website from Google Analytics ?

Value: 1000

Array : [“users”, “wheel”, “audio”, “video”]

References –

https://github.com/zserge/jsmn and https://www.json.org/

Android Android Build system Android Commands Android Java Applications Application Libraries Application Stack / User Interface Bash / Shell Scripts Commands and Packages Compilation Content Management System - CMS Core Kernel C Programs Development & Build Development Environment Setup Errors & Failures Flutter git Go Language Programs Hardware Platforms HTML JAVA Programs Kernel & Device Drivers Linux, OS Concepts and Networking Linux Device Drivers Linux Host, Ubuntu, SysAdmin Linux Kernel Linux Networking Middleware Libraries, HAL Monetization / Google AdSense NDK / Middleware / HAL OS Concepts PHP Programming Languages RaspberryPi Scripting and Automation Search Engine Optimisation ( SEO ) Social Media Socurce Code Management ( SCM ) System Administration, Security Testing and Debugging Uncategorized Userspace Utilities Web design and development Wordpress Yocto / Bitbake / Openembedded
Tags:

Leave a Reply / Ask Question