JSON processing in Python: Difference between revisions
Jump to navigation
Jump to search
Line 13: | Line 13: | ||
print(data["details"]["shape"]["texture"]) # displays bumpy | print(data["details"]["shape"]["texture"]) # displays bumpy | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=Safely Navigate a Complex Data Structure= | |||
Suggestions on how to safely recursively navigate a complex data structure: | |||
{{Internal|Python Safely Navigate a Complex Data Structure#Overview|Safely Navigate a Complex Data Structure}} |
Revision as of 00:11, 3 March 2022
Internal
Overview
import json
data = json.loads('{"color":"blue", "size":10, "details":{"shape":{"texture":"bumpy", "orientation":"vertical"}}}')
print(data.get("color")) # displays blue
print(data["color"]) # displays blue
print(data.get("size")) # displays 10
print(data["details"]["shape"]["texture"]) # displays bumpy
Suggestions on how to safely recursively navigate a complex data structure: