This example uses RawMessage to use a precomputed JSON during marshal.
()
| 220 | |
| 221 | // This example uses RawMessage to use a precomputed JSON during marshal. |
| 222 | func ExampleRawMessage_marshal() { |
| 223 | h := json.RawMessage(`{"precomputed": true}`) |
| 224 | |
| 225 | c := struct { |
| 226 | Header *json.RawMessage `json:"header"` |
| 227 | Body string `json:"body"` |
| 228 | }{Header: &h, Body: "Hello Gophers!"} |
| 229 | |
| 230 | b, err := json.MarshalIndent(&c, "", "\t") |
| 231 | if err != nil { |
| 232 | fmt.Println("error:", err) |
| 233 | } |
| 234 | os.Stdout.Write(b) |
| 235 | |
| 236 | // Output: |
| 237 | // { |
| 238 | // "header": { |
| 239 | // "precomputed": true |
| 240 | // }, |
| 241 | // "body": "Hello Gophers!" |
| 242 | // } |
| 243 | } |
| 244 | |
| 245 | func ExampleIndent() { |
| 246 | type Road struct { |
nothing calls this directly
no test coverage detected
searching dependent graphs…