Implemented gjson Example
1. New 2.NewWithTag 3.NewWithOptions
@@ -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
+}
