diff --git a/exporter/exporter.go b/exporter/exporter.go index cd93c0c..8443df3 100644 --- a/exporter/exporter.go +++ b/exporter/exporter.go @@ -23,6 +23,25 @@ func (exp *Exporter) Count() int32 { return exp.count } +func (exp *Exporter) ExportJson() { + var jstr []byte + exp.Write("[") + it := exp.qstore.QuadsAllIterator() + for graph.Next(it) { + exp.count++ + if exp.count > 1 { + exp.Write(",") + } + + jstr, exp.err = json.Marshal(exp.qstore.Quad(it.Result())) + if exp.err != nil { + return + } + exp.Write(string(jstr[:])) + } + exp.Write("]\n") +} + //print out the string quoted, escaped func (exp *Exporter) WriteEscString(str string) { var esc []byte diff --git a/internal/dump.go b/internal/dump.go index ae5f4ef..bf443f9 100644 --- a/internal/dump.go +++ b/internal/dump.go @@ -28,6 +28,7 @@ func Dump(qs graph.QuadStore, outFile, typ string) error { if export.Err() != nil { return export.Err() } + export.ExportJson() if outFile != "-" { fmt.Printf("%d entries were written\n", export.Count())