JSON is a lightweight data-interchange format. Mostly it is used to transfer data between computers.
Note: The file type of json is .json
Data Type | Description |
---|---|
String | A string is a sequence of characters. |
Number | A number is a sequence of digits. |
Boolean | A Boolean is either true or false. |
Null | A Null is an empty value. |
Array | An array is an ordered list of values. Represented By: [] |
Object | An object is a collection of key-value pairs. Represented By: {} |
{ "name": "Bishworaj Poudel", "address": "Pokhara, Nepal", "age": 24, "image": "g", "description": "Hello World, I am Bishworaj Poudel." }
JSON and XML are human-readable formats and are language-independent. JSON is easier than XML.
text = ` { "name": "Bishworaj Poudel", "address": "Pokhara, Nepal", "age": 24, "image": "https://raw.githubusercontent.com/bishworajpoudelofficial/JsonGuide/main/brp.png", "description": "Hello World, I am Bishworaj Poudel." }` obj = JSON.parse(text) console.log(obj.name) console.log(obj.address) console.log(obj.age) console.log(obj.image) console.log(obj.description)
import json text = """ { "name": "Bishworaj Poudel", "address": "Pokhara, Nepal", "age": 24, "image": "https://raw.githubusercontent.com/bishworajpoudelofficial/JsonGuide/main/brp.png", "description": "Hello World, I am Bishworaj Poudel." } """ obj = json.loads(text) print(obj["name"]) print(obj["address"])
import json # This is python object data = { "name":"Bishworaj Poudel", "age":24, "address": "Pokhara, Nepal" } text = json.dumps(data) print(type(text)) print(text)