Tag Archives: JSON for number

JSON Data Types & Syntax

In previous post, JSON Overview explain about background of JSON, reason to use JSON with data exchange web page to/from servers and No SQL database storage with JSON. Now here we discuss about to JSON supporting Data Types and JSON syntax representation with respect to each data types.

JSON Object Syntax

JSON is language independent because of universal data format structures which is almost support by all modern languages. JSON Object follows below syntax for handling different type of data:

  • JSON object are surrounded with curly braces ({}).
  • JSON object data are written in key/value pairs to represent an object, record, Map, list, array etc.
  • JSON key and value are separated by a colon.
  • JSON objects each key/value pair is separated by a comma (,).
  • JSON keys are strings, written in double quotes(“”) and values can be any data type supported by JSON.
  • JSON Object for list of values (an array, vector, list or sequence) are store in form of array and represent as square braces ([]).

JSON Supported Data Types

JSON data can be represent with following data types:

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

JSON Example

Here is Student detail JSON representation which considers all the above data types and Syntax rules. This example will help you to understand JSON representation with respect to each type of data.

Student JSON Object

JSON for String Value

In JSON string values are represented in double quote (“”);

	"firstName" : "Saurabh",
	"lastName" : "Gupta"

JSON for Number Value

In JSON, number values such as (integer, float, double) values are not required  double quotes.

{"rollNumber" : 11}

JSON for Boolean Value

In JSON, to represent Boolean allowed values are true/false and not required double quotes.

{"permanent" : false}

JSON for an Array

In JSON, Array values are represent in square braces ([]) as shown for cities and phoneNumbers.

"phoneNumbers" : [ 2233445566, 3344556677 ],
"cities" : [ "Dallas", "San Antonio", "Irving" ]

JSON for a Map

In JSON, Map represent as object with in curly braces and each key and value of Map write same way as write properties of Object.

"properties" : {
    "play" : "Badminton",
    "interst" : "Math",
    "age" : "34 years"

JSON for an Object

In JSON, Object represent with in curly braces. Here address is internal object of student.

	"address" : {
		"addressLine" : "Lake Union Hill Way",
		"city" : "Atlanta",
		"zipCode" : 50005

JSON for Null

In JSON, null values are write as below.

{"middleName" : null}

Now you have learned about JSON supported data types and there representation in JSON. In next post you will learn about JSON parsers for serialization and deserialization to/from Java objects. JSON Parsers

You would like to see

Follow below link to learn more on JSON and  JSON issues solutions: