Converts an AST to JSON.