Commit c95c27a9 authored by Russ Cox's avatar Russ Cox

json: expose map in generic representation

R=r, r1
https://golang.org/cl/157146
parent 8ebd7f71
...@@ -33,6 +33,7 @@ type Json interface { ...@@ -33,6 +33,7 @@ type Json interface {
Get(s string) Json; // field lookup (MapKind) Get(s string) Json; // field lookup (MapKind)
Elem(i int) Json; // element lookup (ArrayKind) Elem(i int) Json; // element lookup (ArrayKind)
Len() int; // length (ArrayKind, MapKind) Len() int; // length (ArrayKind, MapKind)
Map() map[string]Json; // map form (MapKind)
} }
// JsonToString returns the textual JSON syntax representation // JsonToString returns the textual JSON syntax representation
...@@ -63,6 +64,7 @@ func (*_Null) Bool() bool { return false } ...@@ -63,6 +64,7 @@ func (*_Null) Bool() bool { return false }
func (*_Null) Get(s string) Json { return Null } func (*_Null) Get(s string) Json { return Null }
func (*_Null) Elem(int) Json { return Null } func (*_Null) Elem(int) Json { return Null }
func (*_Null) Len() int { return 0 } func (*_Null) Len() int { return 0 }
func (*_Null) Map() map[string]Json { return nil }
type _String struct { type _String struct {
s string; s string;
...@@ -158,6 +160,7 @@ func (j *_Map) String() string { ...@@ -158,6 +160,7 @@ func (j *_Map) String() string {
s += "}"; s += "}";
return s; return s;
} }
func (j *_Map) Map() map[string]Json { return j.m }
// Walk evaluates path relative to the JSON object j. // Walk evaluates path relative to the JSON object j.
// Path is taken as a sequence of slash-separated field names // Path is taken as a sequence of slash-separated field names
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
package json package json
import ( import (
"reflect";
"testing"; "testing";
) )
...@@ -73,4 +74,7 @@ func TestJsonMap(t *testing.T) { ...@@ -73,4 +74,7 @@ func TestJsonMap(t *testing.T) {
t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v) t.Errorf("MapTest: Walk(%#q) => %v, want %v", k, v1, v)
} }
} }
if !reflect.DeepEqual(values, mapv.Map()) {
t.Errorf("DeepEqual(values, mapv.Map()) failed")
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment