Skip to content

Commit 85e5e08

Browse files
committed
Add before & after
1 parent 0f0f44b commit 85e5e08

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,43 @@ configuration files, feature flags, and analytics payloads.
77

88
---
99

10+
## 🔁 Before vs After Using DynamicJSON
11+
12+
### ❌ Before (Vanilla Decoding)
13+
14+
```swift
15+
struct Raw: Decodable {
16+
let feature_toggle: String?
17+
let darkMode: String?
18+
}
19+
20+
let decoded = try? JSONDecoder().decode(Raw.self, from: jsonData)
21+
22+
let isEnabled = decoded?.feature_toggle == "true"
23+
let isDark = decoded?.darkMode == "on"
24+
```
25+
26+
- You need to define intermediate models
27+
- Compare strings manually
28+
- Deal with missing keys and nils everywhere
29+
30+
---
31+
32+
### ✅ After (Using DynamicJSON)
33+
34+
```swift
35+
let json = try JSONDecoder().decode(DynamicJSON.self, from: jsonData)
36+
37+
let isEnabled = json.featureToggle.bool
38+
let isDark = json.darkMode.bool
39+
```
40+
41+
- No need for models
42+
- One-line type-safe checks
43+
- Supports formats like `"yes"`, `"on"`, `"1"`, and more
44+
45+
---
46+
1047
## ✨ Why DynamicJSON?
1148

1249
Working with JSON in Swift can be painful — especially when the structure is inconsistent,
@@ -118,6 +155,8 @@ do {
118155
}
119156
```
120157

158+
---
159+
121160
## 🧠 Smart Key Matching
122161

123162
DynamicJSON will normalize and match keys like:

0 commit comments

Comments
 (0)