diff --git a/bikeshed/messages.py b/bikeshed/messages.py
index 5f17837d25..5bd9a74975 100644
--- a/bikeshed/messages.py
+++ b/bikeshed/messages.py
@@ -3,6 +3,7 @@
import contextlib
import dataclasses
import io
+import json
import sys
from collections import Counter
@@ -253,6 +254,19 @@ def formatMessage(type: str, text: str, lineNum: str | int | None = None) -> str
return f"{text}"
if type == "failure":
return f"{text}"
+ elif state.printMode == "json":
+ if not state.seenMessages:
+ jsonText = "[\n"
+ else:
+ jsonText = ""
+ msg = {"lineNum":lineNum, "messageType":type, "text":text}
+ jsonText += " " + json.dumps(msg)
+ if type in ("success", "failure"):
+ jsonText += "\n]"
+ else:
+ jsonText += ", "
+ return jsonText
+
if type == "message":
return text
if type == "success":