normalizeStringEncodedJSONFields recursively walks a parsed JSON value and normalizes `fields` and `tags` properties in both shapes: JSON-encoded strings (from the REST API / `models.Item`) and already- native JSON objects/arrays (from `pad item show --format json`, BUG-4812). String-encoded values
(v any)
| 245 | // Strings that don't parse as JSON pass through unchanged — covers |
| 246 | // hand-written field values that happen to share a key name. |
| 247 | func normalizeStringEncodedJSONFields(v any) any { |
| 248 | switch x := v.(type) { |
| 249 | case map[string]any: |
| 250 | for k, val := range x { |
| 251 | if k == "fields" || k == "tags" { |
| 252 | switch typed := val.(type) { |
| 253 | case string: |
| 254 | if parsed, ok := tryParseEmbeddedJSON(typed); ok { |
| 255 | if k == "fields" { |
| 256 | parsed = stripDuplicatedFieldsKeys(parsed) |
| 257 | } |
| 258 | x[k] = parsed |
| 259 | continue |
| 260 | } |
| 261 | case map[string]any: |
| 262 | // A full models.Item (it carries workspace_id) always |
| 263 | // arrived with string-encoded fields until BUG-4812 made |
| 264 | // `item show --format json` send them native: treat it |
| 265 | // exactly like the parsed string. Any other native fields |
| 266 | // map (the list summary shape, which has no top-level |
| 267 | // implementation_notes or decision_log to duplicate) |
| 268 | // keeps its old path below. |
| 269 | if _, full := x["workspace_id"]; full && k == "fields" { |
| 270 | x[k] = stripDuplicatedFieldsKeys(typed) |
| 271 | continue |
| 272 | } |
| 273 | } |
| 274 | } |
| 275 | x[k] = normalizeStringEncodedJSONFields(val) |
| 276 | } |
| 277 | return x |
| 278 | case []any: |
| 279 | for i, val := range x { |
| 280 | x[i] = normalizeStringEncodedJSONFields(val) |
| 281 | } |
| 282 | return x |
| 283 | default: |
| 284 | return v |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | // stripDuplicatedFieldsKeys removes implementation_notes and |
| 289 | // decision_log from a parsed fields object. The server hydrates both |