...

Source file src/github.com/launchdarkly/go-jsonstream/v3/jwriter/writer_object_examples_test.go

Documentation: github.com/launchdarkly/go-jsonstream/v3/jwriter

     1  package jwriter
     2  
     3  import (
     4  	"fmt"
     5  )
     6  
     7  func ExampleObjectState_Name() {
     8  	myCustomMarshaler := func(w *Writer) {
     9  		subObject := w.Object()
    10  		subObject.Name("yes").Bool(true)
    11  		subObject.End()
    12  	}
    13  
    14  	w := NewWriter()
    15  
    16  	obj := w.Object()
    17  	myCustomMarshaler(obj.Name("subObject"))
    18  	obj.End()
    19  
    20  	fmt.Println(string(w.Bytes()))
    21  	// Output: {"subObject":{"yes":true}}
    22  }
    23  
    24  func ExampleObjectState_Maybe() {
    25  	w := NewWriter()
    26  	obj := w.Object()
    27  	obj.Maybe("notPresent", false).Int(1)
    28  	obj.Maybe("present", true).Int(2)
    29  	obj.End()
    30  
    31  	fmt.Println(string(w.Bytes()))
    32  	// Output: {"present":2}
    33  }
    34  

View as plain text