Skip to content

Commit 0f0f44b

Browse files
committed
Update readme
1 parent c1609d0 commit 0f0f44b

File tree

1 file changed

+30
-26
lines changed

1 file changed

+30
-26
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -103,36 +103,40 @@ import DynamicJSON
103103
```
104104

105105
```swift
106-
let json = try JSONDecoder().decode(DynamicJSON.self, from: jsonData)
107-
108-
let isEnabled = json.featureToggle.bool // true
109-
let maxItems = json["maxItems"].int // 25
110-
let discount = json.discountRate.double // 12.5
111-
let launch = json.launchDate.as(Date.self) // 2025-01-01
112-
113-
let emailOn = json.settings.notifications.email.bool // true
114-
let pushOn = json["settings.notifications.push"].bool // false
106+
do {
107+
let json = try JSONDecoder().decode(DynamicJSON.self, from: jsonData)
108+
109+
let isEnabled = json.featureToggle.bool // true
110+
let maxItems = json["maxItems"].int // 25
111+
let discount = json.discountRate.double // 12.5
112+
let launch = json.launchDate.as(Date.self) // 2025-01-01
113+
114+
let emailOn = json.settings.notifications.email.bool // true
115+
let pushOn = json["settings.notifications.push"].bool // false
116+
} catch {
117+
print("Failed to decode JSON: \(error)")
118+
}
115119
```
116120

117121
## 🧠 Smart Key Matching
118122

119123
DynamicJSON will normalize and match keys like:
120-
β€’ "FeatureToggle" β†’ "feature_toggle"
121-
β€’ "darkMode" β†’ "dark_mode"
122-
β€’ "beta-feature-x" β†’ "beta_feature_x"
123-
β€’ "FEATURETOGGLE" β†’ "feature_toggle"
124-
β€’ "featurTogle" β†’ fuzzy match β†’ "feature_toggle"
124+
β€’ "FeatureToggle" β†’ "feature_toggle"
125+
β€’ "darkMode" β†’ "dark_mode"
126+
β€’ "beta-feature-x" β†’ "beta_feature_x"
127+
β€’ "FEATURETOGGLE" β†’ "feature_toggle"
128+
β€’ "featurTogle" β†’ fuzzy match β†’ "feature_toggle"
125129

126130
πŸ“… Date Parsing
127131

128132
Supports:
129-
β€’ 2024-01-01T12:34:56Z
130-
β€’ 2024-01-01T12:34:56.123Z
131-
β€’ 2024-01-01 12:34:56
132-
β€’ 2024-01-01
133-
β€’ 01/01/2024
134-
β€’ 01-01-2024
135-
β€’ UNIX timestamp: 1704067200 or 1704067200000
133+
β€’ 2024-01-01T12:34:56Z
134+
β€’ 2024-01-01T12:34:56.123Z
135+
β€’ 2024-01-01 12:34:56
136+
β€’ 2024-01-01
137+
β€’ 01/01/2024
138+
β€’ 01-01-2024
139+
β€’ UNIX timestamp & with milisoconds: 1704067200 or 1704067200000
136140

137141
## πŸ”¬ API
138142

@@ -157,8 +161,8 @@ json.isNull β†’ Bool
157161
## πŸ§ͺ Testing
158162

159163
Includes a full real-world test case covering:
160-
β€’ All primitive types
161-
β€’ Arrays and nested keys
162-
β€’ Date strings and timestamps
163-
β€’ Fuzzy and normalized keys
164-
β€’ Null and missing key handling
164+
β€’ All primitive types
165+
β€’ Arrays and nested keys
166+
β€’ Date strings and timestamps
167+
β€’ Fuzzy and normalized keys
168+
β€’ Null and missing key handling

0 commit comments

Comments
Β (0)