I'm trying to convert list of objects to JSON, but it won't serialise it properly
import marshal
type
DocItem = object of RootObj
tags: seq[string]
TextDoc = object of DocItem
text: string
TodoDoc = object of DocItem
todo: string
var docs: seq[ref DocItem]
proc to_ref[T](o: T): ref T =
result.new
result[] = o
docs.add TextDoc(text: "some doc", tags: @["help"]).to_ref
docs.add TodoDoc(todo: "some todo").to_ref
echo $$docs
The output is:
[[4312834120, {"tags": ["help"]}], [4312834280, {"tags": []}]]
While I need it to be
[{"text": "some doc", "tags": ["help"]}, {"todo": "some todo", "tags": []}]
Also, is there a way to configure marshal
to output pretty JSON?