diff --git a/encoding/gjson/gjson_z_example_new_test.go b/encoding/gjson/gjson_z_example_new_test.go index 644e567c4..a077f280c 100644 --- a/encoding/gjson/gjson_z_example_new_test.go +++ b/encoding/gjson/gjson_z_example_new_test.go @@ -72,3 +72,61 @@ func Example_newFromStructWithTag() { // 100 // engineer } + +func ExampleNew() { + jsonContent := `{"name":"john", "score":"100"}` + j := gjson.New(jsonContent) + fmt.Println(j.Get("name")) + fmt.Println(j.Get("score")) + + // Output: + // john + // 100 +} + +func ExampleNewWithTag() { + type Me struct { + Name string `tag:"name"` + Score int `tag:"score"` + Title string + } + me := Me{ + Name: "john", + Score: 100, + Title: "engineer", + } + j := gjson.NewWithTag(me, "tag") + fmt.Println(j.Get("name")) + fmt.Println(j.Get("score")) + fmt.Println(j.Get("Title")) + + // Output: + // john + // 100 + // engineer +} + +func ExampleNewWithOptions() { + type Me struct { + Name string `tag:"name"` + Score int `tag:"score"` + Title string + } + me := Me{ + Name: "john", + Score: 100, + Title: "engineer", + } + + j := gjson.NewWithOptions(me, gjson.Options{ + Tags: "tag", + }) + fmt.Println(j.Get("name")) + fmt.Println(j.Get("score")) + fmt.Println(j.Get("Title")) + + // Output: + // john + // 100 + // engineer +}