Working with JSON in Python

In the following programs you will learn that how to read JSON data by reading Keys and Values of JSON array.

Program Dictionary Printing Values of Names

Program

mystaf = {'HiLaLs':"Software Developer", 'Nawaz':"Web Developer", 'Amir':"Network Administrator"} #assigning value to 'mystaf'.
print(mystaf['HiLaLs']) #printing 'HiLaLs' Value.
print(mystaf['Amir']) #printing 'Amir' Value.
Output
Software Developer
Network Administrator

Program Dictionary Printing All Values of Names

Program

mystaf = {'HiLaLs':"Software Developer", 'Nawaz':"Web Developer", 'Amir':"Network Administrator"} #assigning value to 'mystaf'.
for i in mystaf: #loop loop on 'mystaf' data.
    print(mystaf[i]) #and printing.
Output
Software Developer
Web Developer
Network Administrator

Assigning Dictionary Printing Names

Program

val = {"Fred": 44, "Wilma": 39, "Barney": 40, "Betty": 41}
for i in val.keys(): #assigning values to 'val' and loop looping on it
    print(i, end="   ") #and printing his names.
Output
Fred   Wilma   Barney   Betty
Process finished with exit code 0

Assigning Dictionary Printing Values
Program

val = {"Fred": 44, "Wilma": 39, "Barney": 40, "Betty": 41}
for i in val.values(): #assigning values to 'val' and loop looping on it
    print(i, end="   ")	#and printing his values.
Output
44   39   40   41

Assigning Dictionary Printing Names and Values
Program

val = {"Fred": 44, "Wilma": 39, "Barney": 40, "Betty": 41}
for i, j in val.items(): #assigning values to 'val' and loop looping on it
    print(i, j) #and printing his Names and Values.
Output
Fred 44
Wilma 39
Barney 40
Betty 41