Skip to content

Commit ca31828

Browse files
author
Thomas Charlot
authored
Fix Jsontablewriter: must return slice of *json (#2)
1 parent ce9626b commit ca31828

3 files changed

Lines changed: 10 additions & 10 deletions

File tree

tabify/json_table_writer.go

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import "github.com/datasweet/jsonmap"
44

55
// JSONTableWriter to writes a json array
66
type JSONTableWriter struct {
7-
row map[string]interface{}
8-
table []map[string]interface{}
7+
row *jsonmap.Json
8+
table []*jsonmap.Json
99
}
1010

1111
// OpenRow implements TableWriter interface
1212
func (w *JSONTableWriter) OpenRow() {
13-
w.row = make(map[string]interface{})
13+
w.row = jsonmap.New()
1414
}
1515

1616
// Cell implements TableWriter interface
1717
func (w *JSONTableWriter) Cell(k string, v interface{}) {
1818
if w.row == nil {
1919
w.OpenRow()
2020
}
21-
w.row[k] = v
21+
w.row.Set(k, v)
2222
}
2323

2424
// CloseRow implements TableWriter interface
@@ -27,8 +27,6 @@ func (w *JSONTableWriter) CloseRow() {
2727
}
2828

2929
// Table to gets the output table
30-
func (w *JSONTableWriter) JSON() *jsonmap.Json {
31-
j := jsonmap.New()
32-
j.Set("", w.table)
33-
return j
30+
func (w *JSONTableWriter) JSON() []*jsonmap.Json {
31+
return w.table
3432
}

tabify/tabify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ type TableWriter interface {
1414
}
1515

1616
// JSON to flatten a json
17-
func JSON(j *jsonmap.Json, opt ...Option) (*jsonmap.Json, error) {
17+
func JSON(j *jsonmap.Json, opt ...Option) ([]*jsonmap.Json, error) {
1818
t := newTabify(opt...)
1919
writer := &JSONTableWriter{}
2020

tabify/tabify_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ func testfile(t *testing.T, filename string) {
4949
t.Fatal("json tabify", err)
5050
}
5151
jtw := readJSON(t, "./tests/"+filename+"_expected.json")
52-
assert.JSONEq(t, jtw.Stringify(), jt.Stringify(), "json table writer")
52+
jo := jsonmap.New()
53+
jo.Set("", jt)
54+
assert.JSONEq(t, jtw.Stringify(), jo.Stringify(), "json table writer")
5355

5456
// SliceTableWriter
5557
st, err := Slice(src, KeyExcluder(excluder), KeyFormatter(formatter))

0 commit comments

Comments
 (0)