Python JSON Overview

JSON means JavaScript Object Notation. JSON ki help se data ko ek end se dusre end tak pahuchaya jata hai. Isko simple example se samjhte hain – Suppose kariye apne pass do system hai, jaha first system me python programming use ho rahi hai aur wahi dusre system me C Programming.

Systems me proper communication hone ke liye data ka exchange hona jaruri hai. Ab yaha JSON ek bahut hi important role play karega, kyuki JSON ke syntax ko read karne ki capability har ek programming language ke pass hoti hai issliye JSON ki wajah se ye dono system aapas me proper communication banaye rakhenge.

Python me JSON ek built-in package hai, jise hum directly import kar sakte hain.

json.dumps() function in Python

Python object ko JSON string me convert karne ke dauran json.dumps() function ka use kiya jata hai. Dusre shabdo me bole to Python se JSON parsing ke dauran json.dumps() function ka use kiya jata hai. Example se samajhte hain:

#PYTHON TO JSON

import json

# ‘student’  – Python Object hai
student = {
  “name”“saurav”,
  “age”28,
  “city”“Indore”
}

# python object ka JSON me conversion:
candidate = json.dumps(student)
print(candidate)

json.loads() function in Python

json.loads() function ki functionality json.dumps() function ke opposite hai. Yaha JSON ko python me me convert kiya jata hai. Dusre shabdo me bole to JSON se Python parsing ke dauran json.loads() function ka use kiya jata hai. Example se samajhte hain:

#JSON TO Python

import json

# ‘student’  – JSON  hai
student = ‘{ “name”“saurav”“age”28“city”“Indore” }’

# JSON ka Python object me conversion:
candidate = json.loads(student)
print(candidate)

Python Objects ka JSON se relation

PYTHON

  • dict
  • list
  • tuple
  • str
  • int
  • float
  • True
  • False
  • None

JSON

  • Object
  • Array
  • Array
  • String 
  • Number
  • Number
  • true
  • false
  • null