json export
This commit is contained in:
parent
00b13d2ac1
commit
1e9c6990bb
2 changed files with 20 additions and 0 deletions
|
|
@ -23,6 +23,25 @@ func (exp *Exporter) Count() int32 {
|
||||||
return exp.count
|
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
|
//print out the string quoted, escaped
|
||||||
func (exp *Exporter) WriteEscString(str string) {
|
func (exp *Exporter) WriteEscString(str string) {
|
||||||
var esc []byte
|
var esc []byte
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ func Dump(qs graph.QuadStore, outFile, typ string) error {
|
||||||
if export.Err() != nil {
|
if export.Err() != nil {
|
||||||
return export.Err()
|
return export.Err()
|
||||||
}
|
}
|
||||||
|
export.ExportJson()
|
||||||
|
|
||||||
if outFile != "-" {
|
if outFile != "-" {
|
||||||
fmt.Printf("%d entries were written\n", export.Count())
|
fmt.Printf("%d entries were written\n", export.Count())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue