Not sure if there's a better way of doing this, but then I serialise the AST into a JSON, 's JSON encoder will encode the struct of each node, but I miss the type.

I want to include the node type.

Follow

So what I came up with is a Marshaller for each top level node type, that wraps in a "node" struct (type string and object any), and local type to avoid an infinite loop.

This works fine, but not sure if there's a better way of doing it.

Providing the MarshalJSON for each node isn't terrible.

Sign in to participate in the conversation
Mastodon @ SDF

"I appreciate SDF but it's a general-purpose server and the name doesn't make it obvious that it's about art." - Eugen Rochko