rawJSONObject deserializes a JSON object payload for debug display. If the payload is malformed, it returns a map with "error" and "raw" keys preserving the original content for diagnostics. Callers that consume the result programmatically should check for the "error" key.
(raw json.RawMessage)
| 1853 | // keys preserving the original content for diagnostics. Callers that |
| 1854 | // consume the result programmatically should check for the "error" key. |
| 1855 | func rawJSONObject(raw json.RawMessage) map[string]any { |
| 1856 | if len(raw) == 0 { |
| 1857 | return nil |
| 1858 | } |
| 1859 | |
| 1860 | var object map[string]any |
| 1861 | if err := json.Unmarshal(raw, &object); err != nil { |
| 1862 | return map[string]any{ |
| 1863 | "error": "malformed debug payload", |
| 1864 | "parse_error": err.Error(), |
| 1865 | "raw": string(raw), |
| 1866 | } |
| 1867 | } |
| 1868 | // Guard against JSON literal "null" which unmarshals successfully |
| 1869 | // but leaves the map nil. The DB column is JSONB NOT NULL but |
| 1870 | // that only rejects SQL NULL, not JSONB null. |
| 1871 | if object == nil { |
| 1872 | return map[string]any{} |
| 1873 | } |
| 1874 | return object |
| 1875 | } |
| 1876 | |
| 1877 | func nullRawJSONObject(raw pqtype.NullRawMessage) map[string]any { |
| 1878 | if !raw.Valid { |
no test coverage detected