diff --git a/src/formatters/json.cr b/src/formatters/json.cr index 9e03d21..857723b 100644 --- a/src/formatters/json.cr +++ b/src/formatters/json.cr @@ -4,9 +4,11 @@ module Tartrazine class Json < Formatter property name = "json" - def format(text : String, lexer : Lexer, outp : IO) : Nil + def format(text : String, lexer : Lexer, io : IO?) : String? + outp = io.nil? ? String::Builder.new("") : io tokenizer = Tokenizer.new(lexer, text) outp << Tartrazine::Lexer.collapse_tokens(tokenizer.to_a).to_json + return outp.to_s if io.nil? end end end