@@ -52,7 +52,7 @@ const (
52
52
}`
53
53
)
54
54
55
- var testDocumentJSON interface {}
55
+ var testDocumentJSON any
56
56
57
57
type testStructJSON struct {
58
58
Foo []string `json:"foo"`
@@ -67,7 +67,7 @@ type testStructJSON struct {
67
67
} `json:"obj"`
68
68
}
69
69
70
- type aliasedMap map [string ]interface {}
70
+ type aliasedMap map [string ]any
71
71
72
72
var testStructJSONDoc testStructJSON
73
73
var testStructJSONPtr * testStructJSON
@@ -109,7 +109,7 @@ func TestFullDocument(t *testing.T) {
109
109
t .Errorf ("Get(%v) error %v" , in , err .Error ())
110
110
}
111
111
112
- if len (result .(map [string ]interface {} )) != TestDocumentNBItems {
112
+ if len (result .(map [string ]any )) != TestDocumentNBItems {
113
113
t .Errorf ("Get(%v) = %v, expect full document" , in , result )
114
114
}
115
115
@@ -118,7 +118,7 @@ func TestFullDocument(t *testing.T) {
118
118
t .Errorf ("Get(%v) error %v" , in , err .Error ())
119
119
}
120
120
121
- if len (result .(map [string ]interface {} )) != TestDocumentNBItems {
121
+ if len (result .(map [string ]any )) != TestDocumentNBItems {
122
122
t .Errorf ("Get(%v) = %v, expect full document" , in , result )
123
123
}
124
124
}
@@ -160,7 +160,7 @@ type pointableImpl struct {
160
160
a string
161
161
}
162
162
163
- func (p pointableImpl ) JSONLookup (token string ) (interface {} , error ) {
163
+ func (p pointableImpl ) JSONLookup (token string ) (any , error ) {
164
164
if token == "some" {
165
165
return p .a , nil
166
166
}
@@ -169,7 +169,7 @@ func (p pointableImpl) JSONLookup(token string) (interface{}, error) {
169
169
170
170
type pointableMap map [string ]string
171
171
172
- func (p pointableMap ) JSONLookup (token string ) (interface {} , error ) {
172
+ func (p pointableMap ) JSONLookup (token string ) (any , error ) {
173
173
if token == "swap" {
174
174
return p ["swapped" ], nil
175
175
}
@@ -213,7 +213,7 @@ func TestGetNode(t *testing.T) {
213
213
assert .NoError (t , err )
214
214
assert .Len (t , result , TestNodeObjNBItems )
215
215
216
- result , _ , err = p .Get (aliasedMap (testDocumentJSON .(map [string ]interface {} )))
216
+ result , _ , err = p .Get (aliasedMap (testDocumentJSON .(map [string ]any )))
217
217
assert .NoError (t , err )
218
218
assert .Len (t , result , TestNodeObjNBItems )
219
219
@@ -288,8 +288,8 @@ func TestOtherThings(t *testing.T) {
288
288
p , err = New ("/foo/1" )
289
289
assert .NoError (t , err )
290
290
expected := "hello"
291
- bbb := testDocumentJSON .(map [string ]interface {} )["foo" ]
292
- bbb .([]interface {} )[1 ] = "hello"
291
+ bbb := testDocumentJSON .(map [string ]any )["foo" ]
292
+ bbb .([]any )[1 ] = "hello"
293
293
294
294
v , _ , err := p .Get (testDocumentJSON )
295
295
assert .NoError (t , err )
@@ -371,7 +371,7 @@ func (s *settableDoc) UnmarshalJSON(data []byte) error {
371
371
}
372
372
373
373
// JSONLookup implements an interface to customize json pointer lookup
374
- func (s settableDoc ) JSONLookup (token string ) (interface {} , error ) {
374
+ func (s settableDoc ) JSONLookup (token string ) (any , error ) {
375
375
switch token {
376
376
case "a" :
377
377
return & s .Coll , nil
@@ -383,7 +383,7 @@ func (s settableDoc) JSONLookup(token string) (interface{}, error) {
383
383
}
384
384
385
385
// JSONLookup implements an interface to customize json pointer lookup
386
- func (s * settableDoc ) JSONSet (token string , data interface {} ) error {
386
+ func (s * settableDoc ) JSONSet (token string , data any ) error {
387
387
switch token {
388
388
case "a" :
389
389
switch dt := data .(type ) {
@@ -440,15 +440,15 @@ func (s *settableColl) UnmarshalJSON(data []byte) error {
440
440
}
441
441
442
442
// JSONLookup implements an interface to customize json pointer lookup
443
- func (s settableColl ) JSONLookup (token string ) (interface {} , error ) {
443
+ func (s settableColl ) JSONLookup (token string ) (any , error ) {
444
444
if tok , err := strconv .Atoi (token ); err == nil {
445
445
return & s .Items [tok ], nil
446
446
}
447
447
return nil , fmt .Errorf ("%s is not a valid index" , token )
448
448
}
449
449
450
450
// JSONLookup implements an interface to customize json pointer lookup
451
- func (s * settableColl ) JSONSet (token string , data interface {} ) error {
451
+ func (s * settableColl ) JSONSet (token string , data any ) error {
452
452
if _ , err := strconv .Atoi (token ); err == nil {
453
453
_ , err := SetForToken (s .Items , token , data )
454
454
return err
@@ -476,7 +476,7 @@ func TestSetNode(t *testing.T) {
476
476
477
477
jsonText := `{"a":[{"b": 1, "c": 2}], "d": 3}`
478
478
479
- var jsonDocument interface {}
479
+ var jsonDocument any
480
480
if assert .NoError (t , json .Unmarshal ([]byte (jsonText ), & jsonDocument )) {
481
481
in := "/a/0/c"
482
482
p , err := New (in )
@@ -485,13 +485,13 @@ func TestSetNode(t *testing.T) {
485
485
_ , err = p .Set (jsonDocument , 999 )
486
486
assert .NoError (t , err )
487
487
488
- firstNode := jsonDocument .(map [string ]interface {} )
488
+ firstNode := jsonDocument .(map [string ]any )
489
489
assert .Len (t , firstNode , 2 )
490
490
491
- sliceNode := firstNode ["a" ].([]interface {} )
491
+ sliceNode := firstNode ["a" ].([]any )
492
492
assert .Len (t , sliceNode , 1 )
493
493
494
- changedNode := sliceNode [0 ].(map [string ]interface {} )
494
+ changedNode := sliceNode [0 ].(map [string ]any )
495
495
chNodeVI := changedNode ["c" ]
496
496
if assert .IsType (t , 0 , chNodeVI ) {
497
497
changedNodeValue := chNodeVI .(int )
@@ -503,14 +503,14 @@ func TestSetNode(t *testing.T) {
503
503
504
504
v , err := New ("/a/0" )
505
505
if assert .NoError (t , err ) {
506
- _ , err = v .Set (jsonDocument , map [string ]interface {} {"b" : 3 , "c" : 8 })
506
+ _ , err = v .Set (jsonDocument , map [string ]any {"b" : 3 , "c" : 8 })
507
507
if assert .NoError (t , err ) {
508
- firstNode := jsonDocument .(map [string ]interface {} )
508
+ firstNode := jsonDocument .(map [string ]any )
509
509
assert .Len (t , firstNode , 2 )
510
510
511
- sliceNode := firstNode ["a" ].([]interface {} )
511
+ sliceNode := firstNode ["a" ].([]any )
512
512
assert .Len (t , sliceNode , 1 )
513
- changedNode := sliceNode [0 ].(map [string ]interface {} )
513
+ changedNode := sliceNode [0 ].(map [string ]any )
514
514
assert .Equal (t , 3 , changedNode ["b" ])
515
515
assert .Equal (t , 8 , changedNode ["c" ])
516
516
}
0 commit comments