@@ -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
119123DynamicJSON 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
128132Supports:
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
159163Includes 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