FormatFieldValue renders one field value for a human: a string as itself, a structured value (a json field's object or array) as compact JSON, anything else as Go prints it. Go's own `%v` printed a json field as `[map[name:target …]]`, which is neither JSON nor readable (BUG-3448). Decode the field
(v any)
| 422 | // above 2^53. A JSON null prints as null, which an empty value |
| 423 | // would not say. |
| 424 | func FormatFieldValue(v any) string { |
| 425 | switch t := v.(type) { |
| 426 | case nil: |
| 427 | return "null" |
| 428 | case string: |
| 429 | return t |
| 430 | case json.Number: |
| 431 | return t.String() |
| 432 | case map[string]any, []any: |
| 433 | if b, err := json.Marshal(t); err == nil { |
| 434 | return string(b) |
| 435 | } |
| 436 | } |
| 437 | return fmt.Sprintf("%v", v) |
| 438 | } |
| 439 | |
| 440 | // summariseFieldValue is FormatFieldValue for a one-line summary: a |
| 441 | // structured value is reported by its size, so one json field cannot turn |
no test coverage detected