JSON | Data Types
JSON (JavaScript Object Notation) is most widely used data format for data interchange on the web. JSON is a lightweight text based, data-interchange format and it completely language independent. It is based on a subset of the JavaScript programming language and it is easy to understand and generate.
JSON supports mainly 6 data types:
- string
- number
- boolean
- null
- object
- array
Note: string, number, boolean, null are simple data types or primitives data types whereas object and array are referred as complex data types.
- String: JSON strings must be written in double quotes like C-language there are various special characters(Escape Characters) in JSON that you can use in strings such as \ (backslash), / (forward slash), b (backspace), n (new line), r (carriage return), t (horizontal tab) etc.
Example:
{ "name":"Vivek" } { "city":"Delhi\/India" } here \/ is used for Escape Character / (forward slash).
- Number: Represented in base 10 and octal and hexadecimal formats are not used.
Example:{ "age": 20 } { "percentage": 82.44}
- Boolean: This data type can be either true or false.
Example:{ "result" : true }
- Null: It is just a define nillable value.
Example:{ "result" : true, "grade" : null, "rollno" : 210 }
- Object: It is a set of name or value pairs inserted between {} (curly braces). The keys must be strings and should be unique and multiple key and value pairs are separated by a, (comma).
Syntax:{ key : value, .......}
Example:
{ "Geek":{ "name":"Peter", "age":20, "score": 50.05} }
- Array: It is an ordered collection of values and begins with [ (left bracket) and ends with ] (right bracket). The values of array are separated by ,(comma).
Syntax:[ value, .......]
Example:
{ "geek":[ "Sahil", "Vivek", "Rahul" ] } { "collection" : [ {"id" : 101}, {"id" : 102}, {"id" : 103} ] }
Example of JSON document:
{ "Geeks" : [ { "Geekname" : "Sahil kumar", "subject" : "Data structures", "Articles" : 10 }, { "Geekname" : "Pawan singh", "subject" : "Algorithms", "Articles" : 16 }, { "Geekname" : "Ayush Goel", "subject" : "Networking", "Articles" : 7 } ] }
Recommended Posts:
- Working With JSON Data in Python
- How to convert JSON data to a html table using JavaScript/jQuery ?
- JSON | modify an array value of a JSON object
- Data types in TypeScript
- JavaScript Course | Data Types in JavaScript
- JavaScript JSON
- Javascript | JSON PHP
- JSON web token | JWT
- Difference between JSON and XML
- How to receive JSON POST with PHP
- How to parse JSON in Java
- JavaScript | JSON Arrays
- Python | Sort JSON by value
- Interesting facts about JSON
- JSON Formatting in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : nhyatt0313