Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions examples/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
package main

import (
"encoding/json"
"bytes"
"encoding/json/v2"
"fmt"
"os"
"strings"
)

Expand Down Expand Up @@ -120,16 +120,16 @@ func main() {
// In the examples above we always used bytes and
// strings as intermediates between the data and
// JSON representation on standard out. We can also
// stream JSON encodings directly to `os.Writer`s like
// stream JSON encodings directly to `io.Writer`s like
// `os.Stdout` or even HTTP response bodies.
enc := json.NewEncoder(os.Stdout)
d := map[string]int{"apple": 5, "lettuce": 7}
_ = enc.Encode(d)
var buf bytes.Buffer
_ = json.MarshalWrite(&buf, d)
fmt.Println(buf.String())

// Streaming reads from `os.Reader`s like `os.Stdin`
// or HTTP request bodies is done with `json.Decoder`.
dec := json.NewDecoder(strings.NewReader(str))
// Streaming reads from `io.Reader`s like `os.Stdin`
// or HTTP request bodies is done with `json.UnmarshalRead`.
res1 := response2{}
_ = dec.Decode(&res1)
_ = json.UnmarshalRead(strings.NewReader(str), &res1)
fmt.Println(res1)
}
4 changes: 2 additions & 2 deletions examples/json/json.hash
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
4226a55d93b890ea5296fd237a15b2a7a4cc107a
zeZ4BxQo7ct
525bd5132f98beb6b3a3856061000115f8bc7324
09HfDq_PP3G
2 changes: 1 addition & 1 deletion examples/json/json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ apple

# We've covered the basic of JSON in Go here, but check
# out the [JSON and Go](https://go.dev/blog/json)
# blog post and [JSON package docs](https://pkg.go.dev/encoding/json)
# blog post and the [JSON package docs](https://pkg.go.dev/encoding/json/v2)
# for more.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/mmcgrana/gobyexample

go 1.26.4
go 1.27rc2

require (
github.com/alecthomas/chroma/v2 v2.10.0
Expand Down
28 changes: 14 additions & 14 deletions public/json

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

Loading