Yeah, you really shouldn't use `marshal`, especially when `json` gives you exactly the same output with very few changes: import json type DocKind = enum TextDoc, TodoDoc DocItem = object case kind:DocKind of TextDoc: text: string of TodoDoc: todo: string tags: seq[string] var docs: seq[DocItem] docs.add DocItem(kind:TextDoc, text: "some doc", tags: @["help"]) docs.add DocItem(kind:TodoDoc,todo: "some todo") echo %docs Run
And yes, @alexeypetrushin, I would suggest avoiding inheritance as much as you can. Object variants are the way to go.