JSONValue recursively escapes string values in JSON-compatible data.
(value any)
| 60 | |
| 61 | // JSONValue recursively escapes string values in JSON-compatible data. |
| 62 | func JSONValue(value any) any { |
| 63 | switch typed := value.(type) { |
| 64 | case string: |
| 65 | return String(typed) |
| 66 | case []any: |
| 67 | out := make([]any, len(typed)) |
| 68 | for index, item := range typed { |
| 69 | out[index] = JSONValue(item) |
| 70 | } |
| 71 | return out |
| 72 | case map[string]any: |
| 73 | out := make(map[string]any, len(typed)) |
| 74 | for key, item := range typed { |
| 75 | out[key] = JSONValue(item) |
| 76 | } |
| 77 | return out |
| 78 | default: |
| 79 | return value |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // IsJSONContentType reports whether contentType is application/json or a +json type. |
| 84 | func IsJSONContentType(contentType string) bool { |