diff options
Diffstat (limited to 'json_array')
-rw-r--r-- | json_array/read.go | 18 | ||||
-rw-r--r-- | json_array/write.go | 27 |
2 files changed, 20 insertions, 25 deletions
diff --git a/json_array/read.go b/json_array/read.go index 6334197..786bc2c 100644 --- a/json_array/read.go +++ b/json_array/read.go @@ -15,30 +15,30 @@ const ( stateDead ) -func atomiseValue(value interface{}) []walk.Atom { +func atomiseValue(value interface{}) []walk.AtomOLD { switch v := value.(type) { case nil: - return []walk.Atom{walk.NewAtomNull()} + return []walk.AtomOLD{walk.NewAtomNull()} case bool: - return []walk.Atom{walk.NewAtomBool(v)} + return []walk.AtomOLD{walk.NewAtomBool(v)} case float64: - return []walk.Atom{walk.NewAtomNumber(v)} + return []walk.AtomOLD{walk.NewAtomNumber(v)} case string: - atoms := []walk.Atom{walk.NewAtomStringTerminal()} + atoms := []walk.AtomOLD{walk.NewAtomStringTerminal()} for _, r := range v { atoms = append(atoms, walk.NewAtomStringRune(r)) } atoms = append(atoms, walk.NewAtomStringTerminal()) return atoms case []interface{}: - atoms := []walk.Atom{walk.NewAtomTerminal(walk.ArrayBegin)} + atoms := []walk.AtomOLD{walk.NewAtomTerminal(walk.ArrayBegin)} for _, element := range v { atoms = append(atoms, atomiseValue(element)...) } atoms = append(atoms, walk.NewAtomTerminal(walk.ArrayEnd)) return atoms case map[string]interface{}: - atoms := []walk.Atom{walk.NewAtomTerminal(walk.MapBegin)} + atoms := []walk.AtomOLD{walk.NewAtomTerminal(walk.MapBegin)} for key, element := range v { atoms = append(atoms, atomiseValue(key)...) atoms = append(atoms, atomiseValue(element)...) @@ -90,8 +90,8 @@ func (in *JSONArrayReader) Read() (walk.WalkItem, error) { } in.index += 1 return walk.WalkItem { - Path: []walk.Atom{walk.NewAtomNumber(float64(in.index - 1))}, - Value: atomiseValue(m), + Path: []interface{}{float64(in.index - 1)}, + Value: []interface{}{m}, }, nil case stateEnd: arrayEnd, err := in.decoder.Token() diff --git a/json_array/write.go b/json_array/write.go index 4d202c4..aaa2851 100644 --- a/json_array/write.go +++ b/json_array/write.go @@ -7,7 +7,7 @@ import ( "encoding/json" ) -func assembleValue(atoms []walk.Atom) (interface{}, []walk.Atom) { +func assembleValue(atoms []walk.AtomOLD) (interface{}, []walk.AtomOLD) { if len(atoms) == 0 { panic("Missing JSON value in output") } @@ -89,21 +89,16 @@ func assembleValue(atoms []walk.Atom) (interface{}, []walk.Atom) { } } -func outputValue(atoms []walk.Atom, writer *bufio.Writer) { - if len(atoms) == 0 { - return - } - value, atoms := assembleValue(atoms) - if len(atoms) != 0 { - panic("Tried to output more than one JSON value") - } - bytes, err := json.MarshalIndent(value, "\t", "\t") - if err != nil { - panic("Error marshalling json into bytes") - } - _, err = writer.Write(bytes) - if err != nil { - panic("Error writing value") +func outputValue(values []interface{}, writer *bufio.Writer) { + for _, value := range values { + bytes, err := json.MarshalIndent(value, "\t", "\t") + if err != nil { + panic("Error marshalling json into bytes") + } + _, err = writer.Write(bytes) + if err != nil { + panic("Error writing value") + } } } |