Python JSON: Access only unique key value of a Python object
Write a Python program to access only unique key value of a Python object.
Sample Solution:-
Python Code:
import json
python_obj = '{"a": 1, "a": 2, "a": 3, "a": 4, "b": 1, "b": 2}'
print("Original Python object:")
print(python_obj)
json_obj = json.loads(python_obj)
print("\nUnique Key in a JSON object:")
print(json_obj)
Output:
Original Python object: {"a": 1, "a": 2, "a": 3, "a": 4, "b": 1, "b": 2} Unique Key in a JSON object: {'a': 4, 'b': 2}
Flowchart:
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a Python program to check whether a JSON string contains complex object or not.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics