all: import encoding/json/v2 from the standard library

As of Go 1.27, encoding/json/v2 and encoding/json/jsontext are in the
standard library, and github.com/go-json-experiment/json and its
jsontext package are just aliases for them.

Make cmd/jsonimports rewrite go-json-experiment imports to the standard
library instead of the other way around, keeping the jsonv1 and jsonv2
import names, and leave generated files alone. Make cmd/viewer generate
standard library imports, and update everything that imported
go-json-experiment, so no binary links it anymore.

Updates #22811

Change-Id: I4b725434dca9703e6ca0ad30ce94db03919a343f
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
Brad Fitzpatrick committed 2026-12-04 20:40:12 -08:00
1 parent 67489a9581
commit 2dad003b2d
60 files changed
+320 -242

No files matched your search

-3
View File
@@ -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
+67 -26
View File
@@ -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.
+120 -36
View File
@@ -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()
+14 -25
View File
@@ -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.
-3
View File
@@ -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+
+4 -4
View File
@@ -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)
-3
View File
@@ -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
+2 -2
View File
@@ -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"
-3
View File
@@ -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
-3
View File
@@ -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
-3
View File
@@ -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
-3
View File
@@ -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+
-3
View File
@@ -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
+2 -2
View File
@@ -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"
)
+2 -2
View File
@@ -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 {
+2 -2
View File
@@ -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"
)
+2 -3
View File
@@ -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"
+1 -1
View File
@@ -172,4 +172,4 @@
});
};
}
# nix-direnv cache busting line: sha256-o/qFbff3o7PvNxNotnkw3FRz6iPSyOYW36Us1KMNda4=
# nix-direnv cache busting line: sha256-XMzcDXtI+Nag9S9B8qjPuGBV0yO/L5cdMhrVR8IHyC0=
+2 -2
View File
@@ -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="
}
}
+1 -1
View File
@@ -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
+2 -2
View File
@@ -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"
+2 -2
View File
@@ -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"
+3 -3
View File
@@ -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")
}
+2 -2
View File
@@ -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"
+8 -8
View File
@@ -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{
+2 -2
View File
@@ -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"
+3 -4
View File
@@ -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"
+1 -1
View File
@@ -16,4 +16,4 @@
) {
src = ./.;
}).shellNix
# nix-direnv cache busting line: sha256-o/qFbff3o7PvNxNotnkw3FRz6iPSyOYW36Us1KMNda4=
# nix-direnv cache busting line: sha256-XMzcDXtI+Nag9S9B8qjPuGBV0yO/L5cdMhrVR8IHyC0=
+2 -2
View File
@@ -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"
-3
View File
@@ -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
+2 -2
View File
@@ -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"
)
+5 -6
View File
@@ -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)
+9 -9
View File
@@ -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 != "" {
+4 -5
View File
@@ -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
}}
+2 -3
View File
@@ -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.
+5 -5
View File
@@ -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)
+2 -2
View File
@@ -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"
+2 -2
View File
@@ -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"
+2 -2
View File
@@ -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"
+2 -2
View File
@@ -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"
+2 -2
View File
@@ -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"
)
@@ -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"
+2 -2
View File
@@ -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"
+5 -5
View File
@@ -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",
+2 -3
View File
@@ -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
+2 -2
View File
@@ -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"
)
+2 -2
View File
@@ -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"
)
+2 -2
View File
@@ -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"
)
+1 -1
View File
@@ -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"
+1 -1
View File
@@ -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"
+2 -3
View File
@@ -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.
+1 -2
View File
@@ -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) {
+2 -2
View File
@@ -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"
+1 -2
View File
@@ -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) {
+2 -2
View File
@@ -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"
+4 -4
View File
@@ -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)
+3 -2
View File
@@ -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"
)
+2 -3
View File
@@ -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.
+1 -1
View File
@@ -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"
+2 -2
View File
@@ -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"