json export

This commit is contained in:
David Schor 2015-08-10 02:14:10 -04:00
parent 00b13d2ac1
commit 1e9c6990bb
2 changed files with 20 additions and 0 deletions

View file

@ -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

View file

@ -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())