JSON provides data for multiple uses in human-readable format and can be used by many programming languages like C++, C#, Python, Java, Perl, etc. To satisfy their data structure and data type, JSON supports various data types of its own to make things easier. In this tutorial, you will be learning about the data types in JSON.

Data Types in JSON

JSON provides eight data types for dealing with different kinds of data.
  1. Number
  2. String
  3. Boolean
  4. Array
  5. Value
  6. Object
  7. Whitespace
  8. null


Numbers provides floating point double precision data format and does not allow octal or hexadecimal number formats. Moreover, it does not assign NaN or infinity to its variables. The syntax will look something like this:


{ string : nunbervalue, .... }


var ob = {age: 64}

It also has three subcategories:

  1. Integer
  2. Fraction
  3. Exponent


A string is a double-quoted set of character(s) (Unicode) having backslash escaping. It denotes a single character string value, having a string length of one when you say character. The syntax will look something like this:


{ string : "stringdata", ....}


Boolean provides a boolean value of either true, i.e., 1, or false, i.e., 0. The syntax will look something like this:


{ string : true/false, .... }


{ name: 'Alex', age: 20, marks: false }


An array is a collection of multiple values under one name and is enclosed within square braces as in other programming languages and separated by commas. But here, the JSON users can start indexing its value from either 0 or 1. Array elements are used with their keys, which are sequential integer values.
The syntax looks something like this:


[ value1, value2, ….]


  "department": [
      "software_programming": "C++",
      "version": "17"
      "web_development": "HTML",
      "version": "5"
      "IT_management": "Entrepreneurship",
      "type": "startup"


Value provides data which can be of any data type among the following:

  • null
  • array
  • object
  • string
  • true or false
  • number etc


The object provides an unordered collection of data in a name-value pairing format, and you can detect it easily because it keeps enclosed within a pair of curly brackets ({ and }). Between name and value, there is a colon (:) to separate these two entities. It is to be noted that the key/name must have to be a string. The syntax looks something like this:


{ string1 : value1, string2 : value2, ....}


Whitespace provides a gap for readability between tokens of JSON data. This can be done simply with the use of string and space within that double quotes, something like this:


{string:" ",...}


null provides data which has nothing to it or other words; you can say it's variable is empty. Example:


var val_check = null;

Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram