• Ashish Jha's Official Blog
  • ask[@]ashishjha.com

ashish-jha

  • Home
  • Advertise
  • Blog
    • Technology
      • Cloud
      • Devops
      • Hacking
      • Security
      • WordPress
    • Software Development
      • PHP
    • Make Money
      • Blogging
      • Business
      • Domaining
    • Mindset
      • Spiritual
      • Motivation
      • India
    • General
      • Finance
      • Education
      • Health
  • Contact Us
  • Site Map
✕

JSON

  • Home
  • Blog
  • Software Development Basics
  • JSON
January 10, 2021
Categories
  • Basics
Tags

Json stands for JavaScript Object Notation. JSON is an open-standard file format that uses human-readable text to transmit data objects consisting of attribute–value pairs and array data types and is language independent. It is derived from javascript. The official Internet media type for JSON is application/json. JSON filenames use the extension .json.

JSON was created because there was a need for light weight data interchange format. There are other formats also like XML,YAML, HOCON but there was a need for less verbose light weight data interchange format. JSON fulfills all these requirements.

Douglas Crockford originally specified the JSON format in the early 2000s; two competing standards, RFC 8259 and ECMA-404,defined it in 2017. The ECMA standard describes only the allowed syntax, whereas the RFC covers some security and interoperability considerations. The acronym originated at State Software, a company co-founded by Crockford and others in March 2001.

JSON is built on two structures:

  • A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
  • An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.

These are universal data structures. Virtually all modern programming languages support them in one form or another. It makes sense that a data format that is interchangeable with programming languages also be based on these structures.

In JSON, they take on these forms:

An 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).

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

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.

A 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.

A number is very much like a C or Java number, except that the octal and hexadecimal formats are not used.

Sample Json format

{"employees":[
    { "firstName":"John", "lastName":"Doe" },
    { "firstName":"Anna", "lastName":"Smith" },
    { "firstName":"Peter", "lastName":"Jones" }
]}

Sample XML format
<?xml version="1.0" encoding="UTF-8" ?>
<root>
	<employees>
		<firstName>John</firstName>
		<lastName>Doe</lastName>
	</employees>
	<employees>
		<firstName>Anna</firstName>
		<lastName>Smith</lastName>
	</employees>
	<employees>
		<firstName>Peter</firstName>
		<lastName>Jones</lastName>
	</employees>
</root>

Sample YAML format
---
employees:
- firstName: John
  lastName: Doe
- firstName: Anna
  lastName: Smith
- firstName: Peter
  lastName: Jones

Parsing Json

JSON objects are surrounded by curly braces {}.

JSON objects are written in key/value pairs.

Keys must be strings, and values must be a valid JSON data type (string, number, object, array, boolean or null).

Keys and values are separated by a colon.

Each key/value pair is separated by a comma.

Parsin

Most of the programming languages has inbuilt support for reading and writing json data. Generally Json data which you would parse comes in two forms

1: As a Json string

2: As a json file

Parsing Json string in different programming language: For example lets take an example JSON string

{

                “widget”: {

                                “debug”: “on”,

                                “window”: {

                                                “title”: “Sample Konfabulator Widget”,

                                                “name”: “main_window”,

                                                “width”: 500,

                                                “height”: 500

                                },

                                “image”: {

                                                “src”: “Images/Sun.png”,

                                                “name”: “sun1”,

                                                “hOffset”: 250,

                                                “vOffset”: 250,

                                                “alignment”: “center”

                                },

                                “text”: {

                                                “data”: “Click Here”,

                                                “size”: 36,

                                                “style”: “bold”,

                                                “name”: “text1”,

                                                “hOffset”: 250,

                                                “vOffset”: 100,

                                                “alignment”: “center”,

                                                “onMouseUp”: “sun1.opacity = (sun1.opacity / 100) * 90;”

                                }

                }

}

Ashish Jha
Ashish Jha
I am Ashish Jha, Blogger at ashishjha.com blog. I use this blog to write about the things i like and explore. I share my everyday learning experiences with my readers through this blog. I love to answers concerns of my users and readers which you can ask through contact us form located at contact us page of the blog.

Related posts

January 12, 2021

Single Sign On


Read more

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

✕

Categories

  • Basics
  • Blogging
  • Business
  • Databases
  • Devops
  • Domaining
  • Education
  • General
  • Hacking
  • Motivation
  • PHP
  • Sales
  • Security
  • SEO
  • Software Development
  • Technology
  • Wordpress

Recent Posts

  • 0
    An Introduction to Databases
    January 12, 2021
  • 0
    Single Sign On
    January 12, 2021
  • 0
    Installation Of Nginx on Ubuntu 20
    January 11, 2021
  • 0
    JSON
    January 10, 2021
  • 0
    How to Use Sessions Correctly for Persistent Login?
    January 9, 2021

Recent Comments

  • May 23, 2018

    Ashish Jha commented on Should I Call Or Email?

  • May 23, 2018

    Ashish Jha commented on Importance of Education



Recently Added

  • 0
    An Introduction to Databases
    January 12, 2021
  • 0
    Single Sign On
    January 12, 2021
  • 0
    Installation Of Nginx on Ubuntu 20
    January 11, 2021

Worth A Visit

  • Home
  • Advertise
  • Blog
  • Contact Us
  • Site Map

More

  • Who Am I?
  • Community Services
  • Contact Us
  • Business
  • Motivation

Ashish Jha

This is my personal blog where i share my personal views about life and tech explorations.  I always work hard to bring the best & truthful facts through this blog. But, again i disclaim being an authority on any subject. I love learning new things and sharing them with my readers.

Note: Whatever i write on this blog are totally my experiences. If you don’t agree, Simply ignore them and move ahead in life. 

© 2007 - 2022. Ashishjha.com


    This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.