Skip to content

Commit b60140e

Browse files
authored
Update json-parsing-in-python.py
1 parent 5fa26e4 commit b60140e

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

parsing-json/json-parsing-in-python.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,22 @@
7474

7575
available_products = [p for p in products if p["in_stock"]]
7676
print(f"Available: {len(available_products)} products")
77+
78+
# First, let's create a sample config
79+
config_data = {
80+
"api_url": "https://api.example.com/v2",
81+
"timeout": 30,
82+
"retry_attempts": 3,
83+
"enable_logging": True
84+
}
85+
86+
with open('config.json', 'w') as f:
87+
json.dump(config_data, f, indent=2)
88+
89+
with open('config.json', 'r') as f:
90+
config = json.load(f)
91+
92+
print(f"API URL: {config['api_url']}")
93+
print(f"Timeout: {config['timeout']} seconds")
94+
print(f"Logging: {'Enabled' if config['enable_logging'] else 'Disabled'}")
95+

0 commit comments

Comments
 (0)