JSON encodes val as JSON, returning it as a json.RawMessage. Any marshaling errors (which are highly unlikely with correct code) are converted to warnings. This is convenient when filling config structs that require a json.RawMessage, without having to worry about errors.
(val any, warnings *[]Warning)
| 49 | // structs that require a json.RawMessage, without having to worry |
| 50 | // about errors. |
| 51 | func JSON(val any, warnings *[]Warning) json.RawMessage { |
| 52 | b, err := json.Marshal(val) |
| 53 | if err != nil { |
| 54 | if warnings != nil { |
| 55 | *warnings = append(*warnings, Warning{Message: err.Error()}) |
| 56 | } |
| 57 | return nil |
| 58 | } |
| 59 | return b |
| 60 | } |
| 61 | |
| 62 | // JSONModuleObject is like JSON(), except it marshals val into a JSON object |
| 63 | // with an added key named fieldName with the value fieldVal. This is useful |
no test coverage detected