Tree output as plain json

Hi - many thanks for the work :pray:

I have a simple Lezer grammar that allows stuff like this:
( x equals 1 or y equals 2) and (a equals 3 or b equals 4)

When the expression is finished(correct) I need to parse it into a different format and replace some tokens - for example “equals” with something else(an alias). I cannot really do the replacing on the actual doc string, as I might have that exact “token” to be replaced within elements that I do not want to touch.
My thinking was to get the tree into an actual JSON tree and then parse it again and replace whatever is needed. That does not seem like an ideal solution though - and I’m also wondering if there are any examples of json output from tree.cursor().iterate traversal

Can you advise on a way to approach this?

Emitting text output on a tree traversal seems like it should be straightforward. I’d do the transformation in a single step (in the code that emits the text) rather than setting this up as a multi-pass thing.