Iterating through a JSON object in Python

Category > PYTHON || Published on : Friday, January 29, 2021 || Views: 1936 || Iterating through a JSON object in Python


Here Pawan Kumar will explain how to Iterating through a JSON object in Python

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import json
 
def main():
 
    # create a simple JSON array
    jsonString = '{"Name":"Raj","Name":"Kumar","Name":"Ramesh"}'
 
    # change the JSON string into a JSON object
    jsonObject = json.loads(jsonString)
 
    # print the keys and values
    for key in jsonObject:
        value = jsonObject[key]
        print("The key and value are ({}) = ({})".format(key, value))
 
    pass
 
if __name__ == '__main__':
    main()