diff --git a/cmd/derper/depaware.txt b/cmd/derper/depaware.txt index 244fd81c2..64cee9d00 100644 --- a/cmd/derper/depaware.txt +++ b/cmd/derper/depaware.txt @@ -14,9 +14,6 @@ tailscale.com/cmd/derper dependencies: (generated by github.com/tailscale/depawa W 💣 github.com/dblohm7/wingoes from tailscale.com/util/winutil github.com/dgryski/go-metro from github.com/axiomhq/hyperloglog github.com/fxamacker/cbor/v2 from tailscale.com/tka - github.com/go-json-experiment/json from tailscale.com/types/opt+ - github.com/go-json-experiment/json/jsontext from tailscale.com/drive+ - github.com/go-json-experiment/json/v1 from tailscale.com/net/routecheck+ 💣 github.com/go4org/hashtriemap from tailscale.com/derp/derpserver github.com/golang/groupcache/lru from tailscale.com/net/dnscache github.com/hdevalence/ed25519consensus from tailscale.com/tka diff --git a/cmd/jsonimports/format.go b/cmd/jsonimports/format.go index e990d0e67..929d3aec1 100644 --- a/cmd/jsonimports/format.go +++ b/cmd/jsonimports/format.go @@ -15,23 +15,32 @@ import ( "strconv" "strings" + "golang.org/x/tools/go/ast/astutil" + "golang.org/x/tools/imports" "tailscale.com/util/must" ) // mustFormatFile formats a Go source file and adjust "json" imports. // It panics if there are any parsing errors. // -// - "encoding/json" is imported under the name "jsonv1" or "jsonv1std" -// - "encoding/json/v2" is rewritten to import "github.com/go-json-experiment/json" instead -// - "encoding/json/jsontext" is rewritten to import "github.com/go-json-experiment/json/jsontext" instead -// - "github.com/go-json-experiment/json" is imported under the name "jsonv2" -// - "github.com/go-json-experiment/json/v1" is imported under the name "jsonv1" +// - "github.com/go-json-experiment/json" is rewritten to import "encoding/json/v2" instead +// - "github.com/go-json-experiment/json/jsontext" is rewritten to import "encoding/json/jsontext" instead +// - "github.com/go-json-experiment/json/v1" is rewritten to import "encoding/json" instead +// - "encoding/json" is imported under the name "jsonv1" +// - "encoding/json/v2" is imported under the name "jsonv2" // // If no changes to the file is made, it returns input. func mustFormatFile(in []byte) (out []byte) { fset := token.NewFileSet() f := must.Get(parser.ParseFile(fset, "", in, parser.ParseComments)) + // Leave generated files alone; they must match their generator's + // output exactly (e.g. tailscale.com/cmd/viewer still emits + // go-json-experiment imports). + if ast.IsGenerated(f) { + return in + } + // Check for the existence of "json" imports. jsonImports := make(map[string][]*ast.ImportSpec) for _, imp := range f.Imports { @@ -57,19 +66,48 @@ func mustFormatFile(in []byte) (out []byte) { Error: func(err error) {}, }).Check("", fset, []*ast.File{f}, typeInfo) - // Rewrite imports to instead use "github.com/go-json-experiment/json". - // This ensures that code continues to build even if - // goexperiment.jsonv2 is *not* specified. - // As of https://github.com/go-json-experiment/json/pull/186, - // imports to "github.com/go-json-experiment/json" are identical - // to the standard library if built with goexperiment.jsonv2. - for fromPath, toPath := range map[string]string{ - "encoding/json/v2": "github.com/go-json-experiment/json", - "encoding/json/jsontext": "github.com/go-json-experiment/json/jsontext", + // Rewrite imports of "github.com/go-json-experiment/json" packages + // to instead use the standard library, which includes + // "encoding/json/v2" and "encoding/json/jsontext" as of Go 1.27. + // The experiment packages are pure aliases of the standard library, + // so this rewrite never changes types or behavior. + // Delete the old import and add the new one (rather than editing + // the path in place) so that the standard library import lands + // in the standard library import group per goimports convention. + var rewrote bool + renames := make(map[string]string) // mapping of old names to new names + for fromPath, to := range map[string]struct{ path, name string }{ + "github.com/go-json-experiment/json": {"encoding/json/v2", "jsonv2"}, + "github.com/go-json-experiment/json/jsontext": {"encoding/json/jsontext", ""}, // empty name preserves the original import name + "github.com/go-json-experiment/json/v1": {"encoding/json", "jsonv1"}, } { for _, imp := range jsonImports[fromPath] { - imp.Path.Value = strconv.Quote(toPath) - jsonImports[toPath] = append(jsonImports[toPath], imp) + rewrote = true + var oldName string + if imp.Name != nil { + oldName = imp.Name.Name + } + astutil.DeleteNamedImport(fset, f, oldName, fromPath) + + if imps := jsonImports[to.path]; len(imps) > 0 { + // The standard library package is already imported. + // Point old uses at it; the naming loop below gives + // it the canonical name. + if to.name != "" { + renames[importName(imp)] = to.name + } else { + renames[importName(imp)] = importName(imps[0]) + } + } else { + newName := to.name + if newName == "" { + newName = oldName + } + astutil.AddNamedImport(fset, f, newName, to.path) + if to.name != "" { + renames[importName(imp)] = to.name + } + } } delete(jsonImports, fromPath) } @@ -78,22 +116,14 @@ func mustFormatFile(in []byte) (out []byte) { // may exist in our codebase, always explicitly import with // either jsonv1 or jsonv2 in the package name to avoid ambiguities // when looking at a particular Marshal or Unmarshal call site. - renames := make(map[string]string) // mapping of old names to new names deletes := make(map[*ast.ImportSpec]bool) // set of imports to delete for pkgPath, imps := range jsonImports { var newName string switch pkgPath { case "encoding/json": newName = "jsonv1" - // If "github.com/go-json-experiment/json/v1" is also imported, - // then use jsonv1std for "encoding/json" to avoid a conflict. - if len(jsonImports["github.com/go-json-experiment/json/v1"]) > 0 { - newName += "std" - } - case "github.com/go-json-experiment/json": + case "encoding/json/v2": newName = "jsonv2" - case "github.com/go-json-experiment/json/v1": - newName = "jsonv1" } // Rename the import if different than expected. @@ -146,9 +176,20 @@ func mustFormatFile(in []byte) (out []byte) { }), f) } + if !rewrote && len(renames) == 0 && len(deletes) == 0 { + return in + } + + // Run the result through goimports rather than gofmt so that any + // import group we modified is regrouped per the usual convention + // (standard library first, then a blank line, then dotted paths). bb := new(bytes.Buffer) must.Do(format.Node(bb, fset, f)) - return must.Get(format.Source(bb.Bytes())) + return must.Get(imports.Process("", bb.Bytes(), &imports.Options{ + Comments: true, + TabIndent: true, + TabWidth: 8, + })) } // importName is the local package name used for an import. diff --git a/cmd/jsonimports/format_test.go b/cmd/jsonimports/format_test.go index fb3d6fa09..a2b57cadd 100644 --- a/cmd/jsonimports/format_test.go +++ b/cmd/jsonimports/format_test.go @@ -17,12 +17,12 @@ func TestFormatFile(t *testing.T) { import ( "encoding/json" - jsonv2exp "github.com/go-json-experiment/json" + j2 "encoding/json/v2" ) func main() { json.Marshal() - jsonv2exp.Marshal() + j2.Marshal() { var json T // deliberately shadow "json" package name json.Marshal() // should not be re-written @@ -33,7 +33,7 @@ func TestFormatFile(t *testing.T) { import ( jsonv1 "encoding/json" - jsonv2 "github.com/go-json-experiment/json" + jsonv2 "encoding/json/v2" ) func main() { @@ -49,7 +49,7 @@ func TestFormatFile(t *testing.T) { in: `package foobar import ( - "github.com/go-json-experiment/json" + "encoding/json/v2" jsonv2exp "github.com/go-json-experiment/json" ) @@ -60,7 +60,7 @@ func TestFormatFile(t *testing.T) { `, want: `package foobar import ( - jsonv2 "github.com/go-json-experiment/json" + jsonv2 "encoding/json/v2" ) func main() { jsonv2.Marshal() @@ -75,7 +75,7 @@ func TestFormatFile(t *testing.T) { } `, want: `package foobar - import jsonv1 "github.com/go-json-experiment/json/v1" + import jsonv1 "encoding/json" func main() { jsonv1.Marshal() } @@ -84,20 +84,19 @@ func TestFormatFile(t *testing.T) { in: `package foobar import ( "encoding/json" - jsonv1in2 "github.com/go-json-experiment/json/v1" + jsonv1exp "github.com/go-json-experiment/json/v1" ) func main() { json.Marshal() - jsonv1in2.Marshal() + jsonv1exp.Marshal() } `, want: `package foobar import ( - jsonv1std "encoding/json" - jsonv1 "github.com/go-json-experiment/json/v1" + jsonv1 "encoding/json" ) func main() { - jsonv1std.Marshal() + jsonv1.Marshal() jsonv1.Marshal() } `, @@ -105,41 +104,126 @@ func TestFormatFile(t *testing.T) { in: `package foobar import ( "encoding/json" - jsonv1in2 "github.com/go-json-experiment/json/v1" + jsonv2exp "github.com/go-json-experiment/json" + "github.com/go-json-experiment/json/jsontext" ) func main() { json.Marshal() - jsonv1in2.Marshal() - } - `, - want: `package foobar - import ( - jsonv1std "encoding/json" - jsonv1 "github.com/go-json-experiment/json/v1" - ) - func main() { - jsonv1std.Marshal() - jsonv1.Marshal() - } - `, - }, { - in: `package foobar - import ( - "encoding/json" - j2 "encoding/json/v2" - "encoding/json/jsontext" - ) - func main() { - json.Marshal() - j2.Marshal() + jsonv2exp.Marshal() jsontext.NewEncoder } `, want: `package foobar import ( jsonv1 "encoding/json" - jsonv2 "github.com/go-json-experiment/json" + jsonv2 "encoding/json/v2" + "encoding/json/jsontext" + ) + func main() { + jsonv1.Marshal() + jsonv2.Marshal() + jsontext.NewEncoder + } + `, + }, { + in: `package foobar + + import ( + "fmt" + + jsonv2exp "github.com/go-json-experiment/json" "github.com/go-json-experiment/json/jsontext" + "tailscale.com/util/must" + ) + + func main() { + fmt.Println(jsonv2exp.Marshal, jsontext.NewEncoder, must.Get) + } + `, + want: `package foobar + + import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" + "fmt" + + "tailscale.com/util/must" + ) + + func main() { + fmt.Println(jsonv2.Marshal, jsontext.NewEncoder, must.Get) + } + `, + }, { + // A std import added to a group of dotted imports must be + // split off into its own group. + in: `package foobar + + import ( + jsonv2exp "github.com/go-json-experiment/json" + "tailscale.com/util/must" + ) + + func main() { + jsonv2exp.Marshal(must.Get) + } + `, + want: `package foobar + + import ( + jsonv2 "encoding/json/v2" + + "tailscale.com/util/must" + ) + + func main() { + jsonv2.Marshal(must.Get) + } + `, + }, { + // Generated files are left alone. + in: `// Code generated by tailscale.com/cmd/viewer; DO NOT EDIT. + + package foobar + + import ( + jsonv2 "github.com/go-json-experiment/json" + ) + + func main() { + jsonv2.Marshal() + } + `, + want: `// Code generated by tailscale.com/cmd/viewer; DO NOT EDIT. + + package foobar + + import ( + jsonv2 "github.com/go-json-experiment/json" + ) + + func main() { + jsonv2.Marshal() + } + `, + }, { + in: `package foobar + import ( + jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" + "encoding/json/jsontext" + ) + func main() { + jsonv1.Marshal() + jsonv2.Marshal() + jsontext.NewEncoder + } + `, + want: `package foobar + import ( + jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" + "encoding/json/jsontext" ) func main() { jsonv1.Marshal() diff --git a/cmd/jsonimports/jsonimports.go b/cmd/jsonimports/jsonimports.go index 6903844e1..2178e237f 100644 --- a/cmd/jsonimports/jsonimports.go +++ b/cmd/jsonimports/jsonimports.go @@ -4,35 +4,24 @@ // The jsonimports tool formats all Go source files in the repository // to enforce that "json" imports are consistent. // -// With Go 1.25, the "encoding/json/v2" and "encoding/json/jsontext" -// packages are now available under goexperiment.jsonv2. -// This leads to possible confusion over the following: -// -// - "encoding/json" -// - "encoding/json/v2" -// - "encoding/json/jsontext" -// - "github.com/go-json-experiment/json/v1" -// - "github.com/go-json-experiment/json" -// - "github.com/go-json-experiment/json/jsontext" -// +// As of Go 1.27, the "encoding/json/v2" and "encoding/json/jsontext" +// packages are part of the standard library. // In order to enforce consistent usage, we apply the following rules: // -// - Until the Go standard library formally accepts "encoding/json/v2" -// and "encoding/json/jsontext" into the standard library -// (i.e., they are no longer considered experimental), -// we forbid any code from directly importing those packages. -// Go code should instead import "github.com/go-json-experiment/json" -// and "github.com/go-json-experiment/json/jsontext". -// The latter packages contain aliases to the standard library -// if built on Go 1.25 with the goexperiment.jsonv2 tag specified. +// - Imports of the "github.com/go-json-experiment/json" packages +// are forbidden and rewritten to the standard library: +// ".../json" becomes "encoding/json/v2", +// ".../json/jsontext" becomes "encoding/json/jsontext", +// and ".../json/v1" becomes "encoding/json". // -// - Imports of "encoding/json" or "github.com/go-json-experiment/json/v1" -// must be explicitly imported under the package name "jsonv1". -// If both packages need to be imported, then the former should -// be imported under the package name "jsonv1std". +// - Imports of "encoding/json" must be explicitly imported +// under the package name "jsonv1". // -// - Imports of "github.com/go-json-experiment/json" -// must be explicitly imported under the package name "jsonv2". +// - Imports of "encoding/json/v2" must be explicitly imported +// under the package name "jsonv2". +// +// - Generated files are exempt; they must match their generator's +// output exactly. // // The latter two rules exist to provide clarity when reading code. // Without them, it is unclear whether "json.Marshal" refers to v1 or v2. diff --git a/cmd/k8s-operator/depaware.txt b/cmd/k8s-operator/depaware.txt index 654d24543..09ee3a4b3 100644 --- a/cmd/k8s-operator/depaware.txt +++ b/cmd/k8s-operator/depaware.txt @@ -34,9 +34,6 @@ tailscale.com/cmd/k8s-operator dependencies: (generated by github.com/tailscale/ github.com/gaissmai/bart/internal/nodes from github.com/gaissmai/bart github.com/gaissmai/bart/internal/sparse from github.com/gaissmai/bart/internal/nodes github.com/gaissmai/bart/internal/value from github.com/gaissmai/bart+ - github.com/go-json-experiment/json from tailscale.com/types/opt+ - github.com/go-json-experiment/json/jsontext from tailscale.com/logtail+ - github.com/go-json-experiment/json/v1 from tailscale.com/net/routecheck+ github.com/go-logr/logr from github.com/go-logr/logr/slogr+ github.com/go-logr/logr/slogr from github.com/go-logr/zapr github.com/go-logr/zapr from sigs.k8s.io/controller-runtime/pkg/log/zap+ diff --git a/cmd/netlogfmt/main.go b/cmd/netlogfmt/main.go index af7baae46..71a801a92 100644 --- a/cmd/netlogfmt/main.go +++ b/cmd/netlogfmt/main.go @@ -27,7 +27,9 @@ package main import ( "cmp" "encoding/base64" - "encoding/json" + jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "flag" "fmt" "io" @@ -42,8 +44,6 @@ import ( "time" "github.com/dsnet/try" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/tailcfg" "tailscale.com/tstime" "tailscale.com/types/bools" @@ -367,7 +367,7 @@ func mustLoadTailnetNodes() { var m struct { Devices []netlogtype.Node `json:"devices"` } - must.Do(json.Unmarshal(b, &m)) + must.Do(jsonv1.Unmarshal(b, &m)) // Construct a mapping of Tailscale IP addresses to node information. tailnetNodesByAddr = make(map[netip.Addr]netlogtype.Node) diff --git a/cmd/stund/depaware.txt b/cmd/stund/depaware.txt index 6232b6c8f..2b5a91f87 100644 --- a/cmd/stund/depaware.txt +++ b/cmd/stund/depaware.txt @@ -3,9 +3,6 @@ tailscale.com/cmd/stund dependencies: (generated by github.com/tailscale/depawar 💣 crypto/internal/entropy/v1.0.0 from crypto/internal/fips140/drbg github.com/beorn7/perks/quantile from github.com/prometheus/client_golang/prometheus 💣 github.com/cespare/xxhash/v2 from github.com/prometheus/client_golang/prometheus - github.com/go-json-experiment/json from tailscale.com/types/opt+ - github.com/go-json-experiment/json/jsontext from tailscale.com/tailcfg+ - github.com/go-json-experiment/json/v1 from tailscale.com/types/logger github.com/munnerz/goautoneg from github.com/prometheus/common/expfmt 💣 github.com/prometheus/client_golang/prometheus from tailscale.com/tsweb/promvarz github.com/prometheus/client_golang/prometheus/internal from github.com/prometheus/client_golang/prometheus diff --git a/cmd/tailscale/cli/routecheck.go b/cmd/tailscale/cli/routecheck.go index fdc632a54..98eaba939 100644 --- a/cmd/tailscale/cli/routecheck.go +++ b/cmd/tailscale/cli/routecheck.go @@ -8,14 +8,14 @@ package cli import ( "cmp" "context" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "flag" "fmt" "slices" "strings" "text/tabwriter" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "github.com/peterbourgon/ff/v3/ffcli" "tailscale.com/cmd/tailscale/jsonoutput" diff --git a/cmd/tailscale/depaware.txt b/cmd/tailscale/depaware.txt index 6289985b8..b47e84464 100644 --- a/cmd/tailscale/depaware.txt +++ b/cmd/tailscale/depaware.txt @@ -122,9 +122,6 @@ tailscale.com/cmd/tailscale dependencies: (generated by github.com/tailscale/dep github.com/gaissmai/bart/internal/nodes from github.com/gaissmai/bart github.com/gaissmai/bart/internal/sparse from github.com/gaissmai/bart/internal/nodes github.com/gaissmai/bart/internal/value from github.com/gaissmai/bart+ - github.com/go-json-experiment/json from tailscale.com/types/opt+ - github.com/go-json-experiment/json/jsontext from tailscale.com/cmd/tailscale/cli+ - github.com/go-json-experiment/json/v1 from tailscale.com/net/routecheck+ L 💣 github.com/godbus/dbus/v5 from fyne.io/systray+ L github.com/godbus/dbus/v5/introspect from fyne.io/systray+ L github.com/godbus/dbus/v5/prop from fyne.io/systray diff --git a/cmd/tailscaled/depaware-min.txt b/cmd/tailscaled/depaware-min.txt index d17c26e28..e021fad00 100644 --- a/cmd/tailscaled/depaware-min.txt +++ b/cmd/tailscaled/depaware-min.txt @@ -9,9 +9,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/gaissmai/bart/internal/nodes from github.com/gaissmai/bart github.com/gaissmai/bart/internal/sparse from github.com/gaissmai/bart/internal/nodes github.com/gaissmai/bart/internal/value from github.com/gaissmai/bart+ - github.com/go-json-experiment/json from tailscale.com/drive+ - github.com/go-json-experiment/json/jsontext from tailscale.com/drive+ - github.com/go-json-experiment/json/v1 from tailscale.com/types/logger github.com/golang/groupcache/lru from tailscale.com/net/dnscache 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/netmon github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink diff --git a/cmd/tailscaled/depaware-minbox.txt b/cmd/tailscaled/depaware-minbox.txt index 6edd3abca..97940e117 100644 --- a/cmd/tailscaled/depaware-minbox.txt +++ b/cmd/tailscaled/depaware-minbox.txt @@ -9,9 +9,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/gaissmai/bart/internal/nodes from github.com/gaissmai/bart github.com/gaissmai/bart/internal/sparse from github.com/gaissmai/bart/internal/nodes github.com/gaissmai/bart/internal/value from github.com/gaissmai/bart+ - github.com/go-json-experiment/json from tailscale.com/drive+ - github.com/go-json-experiment/json/jsontext from tailscale.com/drive+ - github.com/go-json-experiment/json/v1 from tailscale.com/types/logger github.com/golang/groupcache/lru from tailscale.com/net/dnscache 💣 github.com/jsimonetti/rtnetlink from tailscale.com/net/netmon github.com/jsimonetti/rtnetlink/internal/unix from github.com/jsimonetti/rtnetlink diff --git a/cmd/tailscaled/depaware.txt b/cmd/tailscaled/depaware.txt index 576afe4b2..846e1c712 100644 --- a/cmd/tailscaled/depaware.txt +++ b/cmd/tailscaled/depaware.txt @@ -116,9 +116,6 @@ tailscale.com/cmd/tailscaled dependencies: (generated by github.com/tailscale/de github.com/gaissmai/bart/internal/nodes from github.com/gaissmai/bart github.com/gaissmai/bart/internal/sparse from github.com/gaissmai/bart/internal/nodes github.com/gaissmai/bart/internal/value from github.com/gaissmai/bart+ - github.com/go-json-experiment/json from tailscale.com/types/opt+ - github.com/go-json-experiment/json/jsontext from tailscale.com/logtail+ - github.com/go-json-experiment/json/v1 from tailscale.com/feature/routecheck+ W 💣 github.com/go-ole/go-ole from github.com/go-ole/go-ole/oleutil+ W 💣 github.com/go-ole/go-ole/oleutil from tailscale.com/wgengine/winnet L 💣 github.com/godbus/dbus/v5 from tailscale.com/net/dns+ diff --git a/cmd/tsidp/depaware.txt b/cmd/tsidp/depaware.txt index e6db19a1e..53d5de04d 100644 --- a/cmd/tsidp/depaware.txt +++ b/cmd/tsidp/depaware.txt @@ -28,9 +28,6 @@ tailscale.com/cmd/tsidp dependencies: (generated by github.com/tailscale/depawar github.com/go-jose/go-jose/v4/cipher from github.com/go-jose/go-jose/v4 github.com/go-jose/go-jose/v4/json from github.com/go-jose/go-jose/v4+ github.com/go-jose/go-jose/v4/jwt from tailscale.com/cmd/tsidp - github.com/go-json-experiment/json from tailscale.com/types/opt+ - github.com/go-json-experiment/json/jsontext from tailscale.com/drive+ - github.com/go-json-experiment/json/v1 from tailscale.com/net/routecheck+ L 💣 github.com/godbus/dbus/v5 from tailscale.com/net/dns github.com/golang/groupcache/lru from tailscale.com/net/dnscache github.com/google/btree from gvisor.dev/gvisor/pkg/tcpip/transport/tcp diff --git a/cmd/viewer/tests/tests_view.go b/cmd/viewer/tests/tests_view.go index 29be2d78b..e38a1d5a2 100644 --- a/cmd/viewer/tests/tests_view.go +++ b/cmd/viewer/tests/tests_view.go @@ -7,11 +7,11 @@ package tests import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "golang.org/x/exp/constraints" "tailscale.com/types/views" ) diff --git a/cmd/viewer/viewer.go b/cmd/viewer/viewer.go index 21d417878..e4617be78 100644 --- a/cmd/viewer/viewer.go +++ b/cmd/viewer/viewer.go @@ -222,8 +222,8 @@ func genView(buf *bytes.Buffer, it *codegen.ImportTracker, typ *types.Named, fie return } it.Import("jsonv1", "encoding/json") - it.Import("jsonv2", "github.com/go-json-experiment/json") - it.Import("", "github.com/go-json-experiment/json/jsontext") + it.Import("jsonv2", "encoding/json/v2") + it.Import("", "encoding/json/jsontext") it.Import("", "errors") args := struct { diff --git a/drive/drive_view.go b/drive/drive_view.go index 253a2955b..4bc0e45a1 100644 --- a/drive/drive_view.go +++ b/drive/drive_view.go @@ -7,10 +7,10 @@ package drive import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/views" ) diff --git a/feature/routecheck/localapi.go b/feature/routecheck/localapi.go index 7e2b1e780..5b4a6122e 100644 --- a/feature/routecheck/localapi.go +++ b/feature/routecheck/localapi.go @@ -5,13 +5,12 @@ package routecheck import ( "context" + jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" "errors" "net/http" "time" - jsonv2 "github.com/go-json-experiment/json" - jsonv1 "github.com/go-json-experiment/json/v1" - "tailscale.com/ipn/ipnlocal" "tailscale.com/ipn/localapi" "tailscale.com/net/routecheck" diff --git a/flake.nix b/flake.nix index 39803e9b0..c092560ed 100644 --- a/flake.nix +++ b/flake.nix @@ -172,4 +172,4 @@ }); }; } -# nix-direnv cache busting line: sha256-o/qFbff3o7PvNxNotnkw3FRz6iPSyOYW36Us1KMNda4= +# nix-direnv cache busting line: sha256-XMzcDXtI+Nag9S9B8qjPuGBV0yO/L5cdMhrVR8IHyC0= diff --git a/flakehashes.json b/flakehashes.json index fcc60d23f..05de37c5a 100644 --- a/flakehashes.json +++ b/flakehashes.json @@ -4,7 +4,7 @@ "sri": "sha256-Qmy06FkeFkjqCo1FLSD9dO7hTvdo/gC2VACJniuiQBU=" }, "vendor": { - "goModSum": "sha256-wy9n+PKwfi/Oy2MHm2VpX1lWs63p1CE9nORdb5t4o00=", - "sri": "sha256-o/qFbff3o7PvNxNotnkw3FRz6iPSyOYW36Us1KMNda4=" + "goModSum": "sha256-JyDbInAOOwQPjGJroSyp2eFFynN5IaRf574FCuCmsfU=", + "sri": "sha256-XMzcDXtI+Nag9S9B8qjPuGBV0yO/L5cdMhrVR8IHyC0=" } } diff --git a/go.mod b/go.mod index 10c95bc62..cbe8aa3fc 100644 --- a/go.mod +++ b/go.mod @@ -51,7 +51,6 @@ require ( github.com/fxamacker/cbor/v2 v2.9.3 github.com/gaissmai/bart v0.29.0 github.com/go-jose/go-jose/v4 v4.1.4 - github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3 github.com/go-logr/zapr v1.3.0 github.com/go-ole/go-ole v1.3.0 github.com/go4org/hashtriemap v0.0.0-20260925222741-44e5305f85d9 @@ -236,6 +235,7 @@ require ( github.com/go-git/go-billy/v5 v5.9.0 // indirect github.com/go-git/go-git/v5 v5.19.1 // indirect github.com/go-gorp/gorp/v3 v3.1.0 // indirect + github.com/go-json-experiment/json v0.0.0-20260820222146-c27c302e5fc3 // indirect github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-openapi/jsonpointer v1.0.0 // indirect diff --git a/ipn/conffile/serveconf.go b/ipn/conffile/serveconf.go index bd8d6c57f..99f745d22 100644 --- a/ipn/conffile/serveconf.go +++ b/ipn/conffile/serveconf.go @@ -6,6 +6,8 @@ package conffile import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "fmt" "net" @@ -13,8 +15,6 @@ import ( "path" "strings" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/ipn" "tailscale.com/tailcfg" "tailscale.com/types/opt" diff --git a/ipn/ipn_view.go b/ipn/ipn_view.go index b8cd5bf1b..0d6ac311c 100644 --- a/ipn/ipn_view.go +++ b/ipn/ipn_view.go @@ -7,12 +7,12 @@ package ipn import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" "time" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/drive" "tailscale.com/tailcfg" "tailscale.com/tailcfg/peercap" diff --git a/logtail/filch/filch_test.go b/logtail/filch/filch_test.go index 2538233cf..223802397 100644 --- a/logtail/filch/filch_test.go +++ b/logtail/filch/filch_test.go @@ -5,7 +5,8 @@ package filch import ( "bytes" - "encoding/json" + jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" "fmt" "io" "math" @@ -19,7 +20,6 @@ import ( "testing" "time" - jsonv2 "github.com/go-json-experiment/json" "tailscale.com/tstest" "tailscale.com/util/must" ) @@ -358,7 +358,7 @@ func testMaxFileSize(t *testing.T, replaceStderr bool) { break } var entry struct{ FilchIndex, WriteIndex int64 } - must.Do(json.Unmarshal(b, &entry)) + must.Do(jsonv1.Unmarshal(b, &entry)) if entry.FilchIndex == 0 && entry.WriteIndex == 0 { t.Errorf("both indexes are zero") } diff --git a/logtail/logtail.go b/logtail/logtail.go index 7a045d8be..1d4048988 100644 --- a/logtail/logtail.go +++ b/logtail/logtail.go @@ -12,6 +12,8 @@ import ( "context" "crypto/rand" "encoding/binary" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "expvar" "fmt" "io" @@ -28,8 +30,6 @@ import ( "time" "github.com/creachadair/msync/trigger" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/envknob" "tailscale.com/metrics" "tailscale.com/net/netmon" diff --git a/logtail/logtail_test.go b/logtail/logtail_test.go index 2f5f6816b..1256c326e 100644 --- a/logtail/logtail_test.go +++ b/logtail/logtail_test.go @@ -6,7 +6,8 @@ package logtail import ( "bytes" "context" - "encoding/json" + jsonv1 "encoding/json" + "encoding/json/jsontext" "errors" "fmt" "io" @@ -21,7 +22,6 @@ import ( "testing/synctest" "time" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/envknob" "tailscale.com/net/memnet" "tailscale.com/tstest" @@ -235,7 +235,7 @@ func TestParseAndRemoveLogLevel(t *testing.T) { func unmarshalOne(t *testing.T, body []byte) map[string]any { t.Helper() var entries []map[string]any - err := json.Unmarshal(body, &entries) + err := jsonv1.Unmarshal(body, &entries) if err != nil { t.Error(err) } @@ -293,7 +293,7 @@ func TestUploadLogs(t *testing.T) { var all []map[string]any body := <-got - if err := json.Unmarshal(body, &all); err != nil { + if err := jsonv1.Unmarshal(body, &all); err != nil { t.Fatalf("unmarshal %q: %v", body, err) } if len(all) != 2 { @@ -478,7 +478,7 @@ func TestUploadLogs(t *testing.T) { } var all []map[string]any - if err := json.Unmarshal(<-got, &all); err != nil { + if err := jsonv1.Unmarshal(<-got, &all); err != nil { t.Fatal(err) } if len(all) != 3 { @@ -551,7 +551,7 @@ func TestEncode(t *testing.T) { if got != tt.want { t.Errorf("for %q,\n got: %#q\nwant: %#q\n", tt.in, got, tt.want) } - if err := json.Compact(new(bytes.Buffer), buf.buf.Bytes()); err != nil { + if err := jsonv1.Compact(new(bytes.Buffer), buf.buf.Bytes()); err != nil { t.Errorf("invalid output JSON for %q: %s", tt.in, got) } } @@ -644,8 +644,8 @@ func TestUploadMetrics(t *testing.T) { wantUncompressedBytes += int64(tt.origlen) } } - var got map[string]json.RawMessage - if err := json.Unmarshal([]byte(lg.ExpVar().String()), &got); err != nil { + var got map[string]jsonv1.RawMessage + if err := jsonv1.Unmarshal([]byte(lg.ExpVar().String()), &got); err != nil { t.Fatal(err) } for name, want := range map[string]int64{ diff --git a/net/dns/dns_view.go b/net/dns/dns_view.go index 4d54c2613..a790a5b4c 100644 --- a/net/dns/dns_view.go +++ b/net/dns/dns_view.go @@ -7,11 +7,11 @@ package dns import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/dnstype" "tailscale.com/types/views" "tailscale.com/util/dnsname" diff --git a/net/routecheck/report.go b/net/routecheck/report.go index 0073e230f..21cc473cf 100644 --- a/net/routecheck/report.go +++ b/net/routecheck/report.go @@ -5,16 +5,15 @@ package routecheck import ( "cmp" + jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "iter" "maps" "net/netip" "slices" "time" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" - jsonv1 "github.com/go-json-experiment/json/v1" - "tailscale.com/net/routecheck/peernode" "tailscale.com/tailcfg" "tailscale.com/util/clientmetric" diff --git a/shell.nix b/shell.nix index 232ebbb6d..8e450b627 100644 --- a/shell.nix +++ b/shell.nix @@ -16,4 +16,4 @@ ) { src = ./.; }).shellNix -# nix-direnv cache busting line: sha256-o/qFbff3o7PvNxNotnkw3FRz6iPSyOYW36Us1KMNda4= +# nix-direnv cache busting line: sha256-XMzcDXtI+Nag9S9B8qjPuGBV0yO/L5cdMhrVR8IHyC0= diff --git a/tailcfg/tailcfg_view.go b/tailcfg/tailcfg_view.go index 7afd172c4..126e1803e 100644 --- a/tailcfg/tailcfg_view.go +++ b/tailcfg/tailcfg_view.go @@ -7,12 +7,12 @@ package tailcfg import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" "time" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/tailcfg/nodecap" "tailscale.com/types/dnstype" "tailscale.com/types/jsonformat" diff --git a/tsnet/depaware.txt b/tsnet/depaware.txt index d1b0ac441..0f813985f 100644 --- a/tsnet/depaware.txt +++ b/tsnet/depaware.txt @@ -24,9 +24,6 @@ tailscale.com/tsnet dependencies: (generated by github.com/tailscale/depaware) github.com/gaissmai/bart/internal/nodes from github.com/gaissmai/bart github.com/gaissmai/bart/internal/sparse from github.com/gaissmai/bart/internal/nodes github.com/gaissmai/bart/internal/value from github.com/gaissmai/bart+ - github.com/go-json-experiment/json from tailscale.com/types/opt+ - github.com/go-json-experiment/json/jsontext from tailscale.com/drive+ - github.com/go-json-experiment/json/v1 from tailscale.com/net/routecheck+ L 💣 github.com/godbus/dbus/v5 from tailscale.com/net/dns github.com/golang/groupcache/lru from tailscale.com/net/dnscache github.com/google/btree from gvisor.dev/gvisor/pkg/tcpip/transport/tcp diff --git a/types/dnstype/dnstype_view.go b/types/dnstype/dnstype_view.go index e9ef82feb..f56c4a5f7 100644 --- a/types/dnstype/dnstype_view.go +++ b/types/dnstype/dnstype_view.go @@ -7,11 +7,11 @@ package dnstype import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/views" ) diff --git a/types/jsonx/json.go b/types/jsonx/json.go index 36516f495..28708669d 100644 --- a/types/jsonx/json.go +++ b/types/jsonx/json.go @@ -9,12 +9,11 @@ package jsonx import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "fmt" "reflect" - - "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" ) var ( @@ -122,7 +121,7 @@ func MakeInterfaceCoders[T any](valuesByName map[string]T) (c struct { if err := enc.WriteToken(jsontext.String(name)); err != nil { return err } - if err := json.MarshalEncode(enc, *val); err != nil { + if err := jsonv2.MarshalEncode(enc, *val); err != nil { return err } if err := enc.WriteToken(jsontext.EndObject); err != nil { @@ -139,7 +138,7 @@ func MakeInterfaceCoders[T any](valuesByName map[string]T) (c struct { *val = zero // store nil interface value for JSON null return nil case tok.Kind() != '{': - return &json.SemanticError{JSONKind: tok.Kind(), GoType: reflect.TypeFor[T]()} + return &jsonv2.SemanticError{JSONKind: tok.Kind(), GoType: reflect.TypeFor[T]()} } var v reflect.Value switch tok, err := dec.ReadToken(); { @@ -154,7 +153,7 @@ func MakeInterfaceCoders[T any](valuesByName map[string]T) (c struct { } v = reflect.New(t) } - if err := json.UnmarshalDecode(dec, v.Interface()); err != nil { + if err := jsonv2.UnmarshalDecode(dec, v.Interface()); err != nil { return err } *val = v.Elem().Interface().(T) diff --git a/types/jsonx/json_test.go b/types/jsonx/json_test.go index 8b0abbab6..86b856d56 100644 --- a/types/jsonx/json_test.go +++ b/types/jsonx/json_test.go @@ -4,11 +4,11 @@ package jsonx import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "testing" - "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "github.com/google/go-cmp/cmp" ) @@ -45,9 +45,9 @@ func (w *InterfaceWrapper) UnmarshalJSONFrom(dec *jsontext.Decoder) error { } func TestInterfaceCoders(t *testing.T) { - var opts json.Options = json.JoinOptions( - json.WithMarshalers(json.MarshalToFunc(interfaceCoders.Marshal)), - json.WithUnmarshalers(json.UnmarshalFromFunc(interfaceCoders.Unmarshal)), + var opts jsonv2.Options = jsonv2.JoinOptions( + jsonv2.WithMarshalers(jsonv2.MarshalToFunc(interfaceCoders.Marshal)), + jsonv2.WithUnmarshalers(jsonv2.UnmarshalFromFunc(interfaceCoders.Unmarshal)), ) errSkipMarshal := errors.New("skip marshal") @@ -104,13 +104,13 @@ func TestInterfaceCoders(t *testing.T) { }} { t.Run(tt.label, func(t *testing.T) { if tt.wantMarshalError != errSkipMarshal { - switch gotJSON, err := json.Marshal(&tt.wantVal); { + switch gotJSON, err := jsonv2.Marshal(&tt.wantVal); { case !errors.Is(err, tt.wantMarshalError): t.Fatalf("json.Marshal(%v) error = %v, want %v", tt.wantVal, err, tt.wantMarshalError) case string(gotJSON) != tt.wantJSON: t.Fatalf("json.Marshal(%v) = %s, want %s", tt.wantVal, gotJSON, tt.wantJSON) } - switch gotJSON, err := json.Marshal(&tt.wantVal.Interface, opts); { + switch gotJSON, err := jsonv2.Marshal(&tt.wantVal.Interface, opts); { case !errors.Is(err, tt.wantMarshalError): t.Fatalf("json.Marshal(%v) error = %v, want %v", tt.wantVal, err, tt.wantMarshalError) case string(gotJSON) != tt.wantJSON: @@ -120,14 +120,14 @@ func TestInterfaceCoders(t *testing.T) { if tt.wantJSON != "" { gotVal := makeFiller() - if err := json.Unmarshal([]byte(tt.wantJSON), &gotVal); !errors.Is(err, tt.wantUnmarshalError) { + if err := jsonv2.Unmarshal([]byte(tt.wantJSON), &gotVal); !errors.Is(err, tt.wantUnmarshalError) { t.Fatalf("json.Unmarshal(%v) error = %v, want %v", tt.wantJSON, err, tt.wantUnmarshalError) } if d := cmp.Diff(gotVal, tt.wantVal); d != "" { t.Fatalf("json.Unmarshal(%v):\n%s", tt.wantJSON, d) } gotVal = makeFiller() - if err := json.Unmarshal([]byte(tt.wantJSON), &gotVal.Interface, opts); !errors.Is(err, tt.wantUnmarshalError) { + if err := jsonv2.Unmarshal([]byte(tt.wantJSON), &gotVal.Interface, opts); !errors.Is(err, tt.wantUnmarshalError) { t.Fatalf("json.Unmarshal(%v) error = %v, want %v", tt.wantJSON, err, tt.wantUnmarshalError) } if d := cmp.Diff(gotVal, tt.wantVal); d != "" { diff --git a/types/logger/logger.go b/types/logger/logger.go index e74cb8a65..5665d8e58 100644 --- a/types/logger/logger.go +++ b/types/logger/logger.go @@ -10,7 +10,8 @@ import ( "bufio" "bytes" "container/list" - "encoding/json" + jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" "fmt" "io" "log" @@ -21,8 +22,6 @@ import ( "context" - jsonv2 "github.com/go-json-experiment/json" - jsonv1 "github.com/go-json-experiment/json/v1" "go4.org/mem" "tailscale.com/envknob" "tailscale.com/util/ctxkey" @@ -47,12 +46,12 @@ type Context context.Context // jenc is a json.Encode + bytes.Buffer pair wired up to be reused in a pool. type jenc struct { buf bytes.Buffer - enc *json.Encoder + enc *jsonv1.Encoder } var jencPool = &sync.Pool{New: func() any { je := new(jenc) - je.enc = json.NewEncoder(&je.buf) + je.enc = jsonv1.NewEncoder(&je.buf) return je }} diff --git a/types/opt/value.go b/types/opt/value.go index 4acff5690..5bc143dc1 100644 --- a/types/opt/value.go +++ b/types/opt/value.go @@ -4,11 +4,10 @@ package opt import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "fmt" "reflect" - - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" ) // Value is an optional value to be JSON-encoded. diff --git a/types/opt/value_test.go b/types/opt/value_test.go index 0b7318299..6d1ce8fb9 100644 --- a/types/opt/value_test.go +++ b/types/opt/value_test.go @@ -4,11 +4,11 @@ package opt import ( - "encoding/json" + jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" "reflect" "testing" - jsonv2 "github.com/go-json-experiment/json" "tailscale.com/types/bools" "tailscale.com/util/must" ) @@ -97,7 +97,7 @@ func TestValue(t *testing.T) { want: bools.IfElse( // Detect whether v1 "encoding/json" supports `omitzero` or not. // TODO(Go1.24): Remove this after `omitzero` is supported. - string(must.Get(json.Marshal(struct { + string(must.Get(jsonv1.Marshal(struct { X int `json:",omitzero"` }{}))) == `{}`, `{"True":true,"False":false}`, // omitzero supported @@ -235,7 +235,7 @@ func TestValue(t *testing.T) { if tt.jsonv2 { j, err = jsonv2.Marshal(tt.in) } else { - j, err = json.Marshal(tt.in) + j, err = jsonv1.Marshal(tt.in) } if err != nil { t.Fatal(err) @@ -254,7 +254,7 @@ func TestValue(t *testing.T) { if tt.jsonv2 { err = jsonv2.Unmarshal(j, out) } else { - err = json.Unmarshal(j, out) + err = jsonv1.Unmarshal(j, out) } if err != nil { t.Fatalf("Unmarshal %#q: %v", j, err) diff --git a/types/persist/persist_view.go b/types/persist/persist_view.go index 0b01f5b53..5351b0bcb 100644 --- a/types/persist/persist_view.go +++ b/types/persist/persist_view.go @@ -7,10 +7,10 @@ package persist import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/tailcfg" "tailscale.com/types/key" "tailscale.com/types/structs" diff --git a/types/prefs/item.go b/types/prefs/item.go index 564e8ffde..eb251dc0c 100644 --- a/types/prefs/item.go +++ b/types/prefs/item.go @@ -4,10 +4,10 @@ package prefs import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "fmt" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/opt" "tailscale.com/types/views" "tailscale.com/util/must" diff --git a/types/prefs/list.go b/types/prefs/list.go index c6881991a..e756de387 100644 --- a/types/prefs/list.go +++ b/types/prefs/list.go @@ -4,12 +4,12 @@ package prefs import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "net/netip" "slices" "time" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "golang.org/x/exp/constraints" "tailscale.com/types/opt" "tailscale.com/types/views" diff --git a/types/prefs/map.go b/types/prefs/map.go index 07cb84f0d..6bd898c1f 100644 --- a/types/prefs/map.go +++ b/types/prefs/map.go @@ -4,11 +4,11 @@ package prefs import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "maps" "net/netip" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "golang.org/x/exp/constraints" "tailscale.com/types/opt" "tailscale.com/types/views" diff --git a/types/prefs/prefs.go b/types/prefs/prefs.go index 01fe1792e..fdb158673 100644 --- a/types/prefs/prefs.go +++ b/types/prefs/prefs.go @@ -19,10 +19,10 @@ package prefs import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/opt" ) diff --git a/types/prefs/prefs_example/prefs_example_view.go b/types/prefs/prefs_example/prefs_example_view.go index aa71c1a89..337d7b65a 100644 --- a/types/prefs/prefs_example/prefs_example_view.go +++ b/types/prefs/prefs_example/prefs_example_view.go @@ -7,11 +7,11 @@ package prefs_example import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/drive" "tailscale.com/tailcfg" "tailscale.com/types/opt" diff --git a/types/prefs/prefs_example/prefs_types.go b/types/prefs/prefs_example/prefs_types.go index e704e6bef..5c187d5ce 100644 --- a/types/prefs/prefs_example/prefs_types.go +++ b/types/prefs/prefs_example/prefs_types.go @@ -11,10 +11,10 @@ package prefs_example import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "net/netip" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/drive" "tailscale.com/tailcfg" "tailscale.com/types/opt" diff --git a/types/prefs/prefs_test.go b/types/prefs/prefs_test.go index ccc37b0a7..6d2da50f9 100644 --- a/types/prefs/prefs_test.go +++ b/types/prefs/prefs_test.go @@ -5,14 +5,14 @@ package prefs import ( "bytes" - "encoding/json" + jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" "reflect" "testing" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "github.com/google/go-cmp/cmp" "tailscale.com/types/views" ) @@ -346,8 +346,8 @@ func TestMarshalUnmarshal(t *testing.T) { }{ { name: "json", - marshal: json.Marshal, - unmarshal: json.Unmarshal, + marshal: jsonv1.Marshal, + unmarshal: jsonv1.Unmarshal, }, { name: "jsonv2", diff --git a/types/prefs/prefs_view_test.go b/types/prefs/prefs_view_test.go index ce4dee726..f21c99e57 100644 --- a/types/prefs/prefs_view_test.go +++ b/types/prefs/prefs_view_test.go @@ -7,11 +7,10 @@ package prefs import ( jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "net/netip" - - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" ) //go:generate go run tailscale.com/cmd/cloner -clonefunc=false -type=TestPrefs,TestBundle,TestValueStruct,TestGenericStruct,TestPrefsGroup -tags=test diff --git a/types/prefs/struct_list.go b/types/prefs/struct_list.go index e1c1863fc..3d9f11b63 100644 --- a/types/prefs/struct_list.go +++ b/types/prefs/struct_list.go @@ -4,12 +4,12 @@ package prefs import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "fmt" "reflect" "slices" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/opt" "tailscale.com/types/views" ) diff --git a/types/prefs/struct_map.go b/types/prefs/struct_map.go index 374d8a92e..134efba05 100644 --- a/types/prefs/struct_map.go +++ b/types/prefs/struct_map.go @@ -4,10 +4,10 @@ package prefs import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "maps" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/opt" "tailscale.com/types/views" ) diff --git a/types/views/views.go b/types/views/views.go index fe70e227f..2b4e9c78b 100644 --- a/types/views/views.go +++ b/types/views/views.go @@ -9,6 +9,8 @@ import ( "bytes" "cmp" jsonv1 "encoding/json" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "fmt" "iter" @@ -16,8 +18,6 @@ import ( "reflect" "slices" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "go4.org/mem" ) diff --git a/types/views/views_test.go b/types/views/views_test.go index 7cdd1ab02..f56eb5199 100644 --- a/types/views/views_test.go +++ b/types/views/views_test.go @@ -5,6 +5,7 @@ package views import ( jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" "fmt" "net/netip" "reflect" @@ -14,7 +15,6 @@ import ( "unsafe" qt "github.com/frankban/quicktest" - jsonv2 "github.com/go-json-experiment/json" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "tailscale.com/types/structs" diff --git a/util/syspolicy/internal/internal.go b/util/syspolicy/internal/internal.go index 4179f26c8..1ad5afd51 100644 --- a/util/syspolicy/internal/internal.go +++ b/util/syspolicy/internal/internal.go @@ -7,8 +7,8 @@ package internal import ( "bytes" + "encoding/json/jsontext" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/lazy" "tailscale.com/util/testenv" "tailscale.com/version" diff --git a/util/syspolicy/setting/origin.go b/util/syspolicy/setting/origin.go index 8ed629e72..ba2750573 100644 --- a/util/syspolicy/setting/origin.go +++ b/util/syspolicy/setting/origin.go @@ -4,10 +4,9 @@ package setting import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "fmt" - - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" ) // Origin describes where a policy or a policy setting is configured. diff --git a/util/syspolicy/setting/policy_scope_test.go b/util/syspolicy/setting/policy_scope_test.go index 9cdbbe7ab..c44d032e4 100644 --- a/util/syspolicy/setting/policy_scope_test.go +++ b/util/syspolicy/setting/policy_scope_test.go @@ -4,10 +4,9 @@ package setting import ( + jsonv2 "encoding/json/v2" "reflect" "testing" - - jsonv2 "github.com/go-json-experiment/json" ) func TestPolicyScopeIsApplicableSetting(t *testing.T) { diff --git a/util/syspolicy/setting/raw_item.go b/util/syspolicy/setting/raw_item.go index 4bfb50faa..2217fde00 100644 --- a/util/syspolicy/setting/raw_item.go +++ b/util/syspolicy/setting/raw_item.go @@ -4,11 +4,11 @@ package setting import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "fmt" "reflect" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "tailscale.com/types/opt" "tailscale.com/types/structs" "tailscale.com/util/syspolicy/pkey" diff --git a/util/syspolicy/setting/raw_item_test.go b/util/syspolicy/setting/raw_item_test.go index 1a40bc829..1c64bfce4 100644 --- a/util/syspolicy/setting/raw_item_test.go +++ b/util/syspolicy/setting/raw_item_test.go @@ -4,12 +4,11 @@ package setting import ( + jsonv2 "encoding/json/v2" "math" "reflect" "strconv" "testing" - - jsonv2 "github.com/go-json-experiment/json" ) func TestMarshalUnmarshalRawValue(t *testing.T) { diff --git a/util/syspolicy/setting/snapshot.go b/util/syspolicy/setting/snapshot.go index 74cadd0be..099bb486a 100644 --- a/util/syspolicy/setting/snapshot.go +++ b/util/syspolicy/setting/snapshot.go @@ -4,6 +4,8 @@ package setting import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "errors" "iter" "maps" @@ -11,8 +13,6 @@ import ( "strings" "time" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" xmaps "golang.org/x/exp/maps" "tailscale.com/util/deephash" "tailscale.com/util/syspolicy/pkey" diff --git a/util/syspolicy/setting/snapshot_test.go b/util/syspolicy/setting/snapshot_test.go index 0385e4aef..d4bf82e5d 100644 --- a/util/syspolicy/setting/snapshot_test.go +++ b/util/syspolicy/setting/snapshot_test.go @@ -5,11 +5,11 @@ package setting import ( "cmp" - "encoding/json" + jsonv1 "encoding/json" + jsonv2 "encoding/json/v2" "testing" "time" - jsonv2 "github.com/go-json-experiment/json" "tailscale.com/util/syspolicy/internal" "tailscale.com/util/syspolicy/pkey" "tailscale.com/util/syspolicy/ptype" @@ -556,7 +556,7 @@ func TestMarshalUnmarshalSnapshot(t *testing.T) { if useJSONv2 { gotJSON, err = jsonv2.Marshal(tt.snapshot) } else { - gotJSON, err = json.Marshal(tt.snapshot) + gotJSON, err = jsonv1.Marshal(tt.snapshot) } if err != nil { t.Fatal(err) @@ -570,7 +570,7 @@ func TestMarshalUnmarshalSnapshot(t *testing.T) { if useJSONv2 { err = jsonv2.Unmarshal(gotJSON, &gotBack) } else { - err = json.Unmarshal(gotJSON, &gotBack) + err = jsonv1.Unmarshal(gotJSON, &gotBack) } if err != nil { t.Fatal(err) diff --git a/util/syspolicy/setting/summary.go b/util/syspolicy/setting/summary.go index 4cb15c7c4..11c76615b 100644 --- a/util/syspolicy/setting/summary.go +++ b/util/syspolicy/setting/summary.go @@ -4,8 +4,9 @@ package setting import ( - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" + "tailscale.com/types/opt" ) diff --git a/wgengine/netlog/netlog.go b/wgengine/netlog/netlog.go index 570ff7918..b7be4d213 100644 --- a/wgengine/netlog/netlog.go +++ b/wgengine/netlog/netlog.go @@ -10,6 +10,8 @@ package netlog import ( "cmp" "context" + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "fmt" "io" "log" @@ -33,9 +35,6 @@ import ( "tailscale.com/util/eventbus" "tailscale.com/util/set" "tailscale.com/wgengine/router" - - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" ) // pollPeriod specifies how often to poll for network traffic. diff --git a/wgengine/netlog/netlog_test.go b/wgengine/netlog/netlog_test.go index a80035fb2..283829292 100644 --- a/wgengine/netlog/netlog_test.go +++ b/wgengine/netlog/netlog_test.go @@ -7,6 +7,7 @@ package netlog import ( "encoding/binary" + jsonv2 "encoding/json/v2" "math/rand/v2" "net/netip" "sync" @@ -14,7 +15,6 @@ import ( "testing/synctest" "time" - jsonv2 "github.com/go-json-experiment/json" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "tailscale.com/tailcfg" diff --git a/wgengine/netlog/record_test.go b/wgengine/netlog/record_test.go index 9d6c31697..b01fb330b 100644 --- a/wgengine/netlog/record_test.go +++ b/wgengine/netlog/record_test.go @@ -6,12 +6,12 @@ package netlog import ( + "encoding/json/jsontext" + jsonv2 "encoding/json/v2" "net/netip" "testing" "time" - jsonv2 "github.com/go-json-experiment/json" - "github.com/go-json-experiment/json/jsontext" "github.com/google/go-cmp/cmp" "github.com/google/go-cmp/cmp/cmpopts" "tailscale.com/tailcfg"