Skip to content

Commit

Permalink
Added json.NewDecoder example (#566)
Browse files Browse the repository at this point in the history
* Update json.go

adding example for json.NewDecoder

* updated as per Contributings.md instructions
  • Loading branch information
bhaskar253 authored Dec 30, 2024
1 parent bc680ed commit 7951241
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
8 changes: 8 additions & 0 deletions examples/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
)

// We'll use these two structs to demonstrate encoding and
Expand Down Expand Up @@ -121,4 +122,11 @@ func main() {
enc := json.NewEncoder(os.Stdout)
d := map[string]int{"apple": 5, "lettuce": 7}
enc.Encode(d)

// We can also decode JSON directly from `os.Reader`
dec := json.NewDecoder(strings.NewReader(str))
res1 := response2{}
dec.Decode(&res1)
fmt.Println(res1)
fmt.Println(res1.Fruits[1])
}
4 changes: 2 additions & 2 deletions examples/json/json.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
35295476f817fe575619b6168273a29eddd7f545
JOQpRGJWAxR
75a5664321dafe10fa623c187b90f079c5319a3c
jR7IEUPQF8T
24 changes: 20 additions & 4 deletions public/json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 7951241

Please sign in to comment.