normalizeStringEncodedJSONFields recursively walks a parsed JSON value, finds string-typed `fields` and `tags` properties, parses them as embedded JSON, and substitutes the native object/array. Additionally drops `implementation_notes` and `decision_log` from the parsed fields object — those entries
(v any)
| 235 | // Strings that don't parse as JSON pass through unchanged — covers |
| 236 | // hand-written field values that happen to share a key name. |
| 237 | func normalizeStringEncodedJSONFields(v any) any { |
| 238 | switch x := v.(type) { |
| 239 | case map[string]any: |
| 240 | for k, val := range x { |
| 241 | if s, ok := val.(string); ok && (k == "fields" || k == "tags") { |
| 242 | if parsed, ok := tryParseEmbeddedJSON(s); ok { |
| 243 | if k == "fields" { |
| 244 | parsed = stripDuplicatedFieldsKeys(parsed) |
| 245 | } |
| 246 | x[k] = parsed |
| 247 | continue |
| 248 | } |
| 249 | } |
| 250 | x[k] = normalizeStringEncodedJSONFields(val) |
| 251 | } |
| 252 | return x |
| 253 | case []any: |
| 254 | for i, val := range x { |
| 255 | x[i] = normalizeStringEncodedJSONFields(val) |
| 256 | } |
| 257 | return x |
| 258 | default: |
| 259 | return v |
| 260 | } |
| 261 | } |
| 262 | |
| 263 | // stripDuplicatedFieldsKeys removes implementation_notes and |
| 264 | // decision_log from a parsed fields object. The server hydrates both |