MCPcopy Create free account
hub / github.com/segmentio/encoding / ExampleRawMessage_marshal

Function ExampleRawMessage_marshal

json/golang_example_test.go:222–243  ·  view source on GitHub ↗

This example uses RawMessage to use a precomputed JSON during marshal.

()

Source from the content-addressed store, hash-verified

220
221// This example uses RawMessage to use a precomputed JSON during marshal.
222func 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
245func ExampleIndent() {
246 type Road struct {

Callers

nothing calls this directly

Calls 1

WriteMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…