diff options
author | Russ Cox <rsc@golang.org> | 2009-11-23 18:11:00 -0800 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-11-23 18:11:00 -0800 |
commit | 8b82e06f3621f78c5d526e1b12c075a79a34218d (patch) | |
tree | 8a51ed7d916578911843baad5e4240564ac9164d | |
parent | 603f00c01546a763d23636656afa2f771cc8ead6 (diff) | |
download | golang-8b82e06f3621f78c5d526e1b12c075a79a34218d.tar.gz |
json: expose map in generic representation
R=r, r1
http://codereview.appspot.com/157146
-rw-r--r-- | src/pkg/json/generic.go | 3 | ||||
-rw-r--r-- | src/pkg/json/generic_test.go | 4 |
2 files changed, 7 insertions, 0 deletions
diff --git a/src/pkg/json/generic.go b/src/pkg/json/generic.go index eed8f9daa..0140b50e4 100644 --- a/src/pkg/json/generic.go +++ b/src/pkg/json/generic.go @@ -33,6 +33,7 @@ type Json interface { Get(s string) Json; // field lookup (MapKind) Elem(i int) Json; // element lookup (ArrayKind) Len() int; // length (ArrayKind, MapKind) + Map() map[string]Json; // map form (MapKind) } // JsonToString returns the textual JSON syntax representation @@ -63,6 +64,7 @@ func (*_Null) Bool() bool { return false } func (*_Null) Get(s string) Json { return Null } func (*_Null) Elem(int) Json { return Null } func (*_Null) Len() int { return 0 } +func (*_Null) Map() map[string]Json { return nil } type _String struct { s string; @@ -158,6 +160,7 @@ func (j *_Map) String() string { s += "}"; return s; } +func (j *_Map) Map() map[string]Json { return j.m } // Walk evaluates path relative to the JSON object j. // Path is taken as a sequence of slash-separated field names diff --git a/src/pkg/json/generic_test.go b/src/pkg/json/generic_test.go index 7fc7bcc55..5b660f268 100644 --- a/src/pkg/json/generic_test.go +++ b/src/pkg/json/generic_test.go @@ -5,6 +5,7 @@ package json import ( + "reflect"; "testing"; ) @@ -73,4 +74,7 @@ func TestJsonMap(t *testing.T) { t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v) } } + if !reflect.DeepEqual(values, mapv.Map()) { + t.Errorf("DeepEqual(values, mapv.Map()) failed") + } } |