From e668598cefe0a8a058d9deae516ac6a7d7afd6d7 Mon Sep 17 00:00:00 2001 From: Asger Hautop Drewsen Date: Mon, 24 Nov 2025 21:34:46 +0100 Subject: [PATCH] axum-extra: Add trailing newline to pretty JSON response (#3526) --- axum-extra/src/response/erased_json.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/axum-extra/src/response/erased_json.rs b/axum-extra/src/response/erased_json.rs index 76c7390e..aa554a7e 100644 --- a/axum-extra/src/response/erased_json.rs +++ b/axum-extra/src/response/erased_json.rs @@ -57,7 +57,10 @@ impl ErasedJson { pub fn pretty(val: T) -> Self { let mut bytes = BytesMut::with_capacity(128); let result = match serde_json::to_writer_pretty((&mut bytes).writer(), &val) { - Ok(()) => Ok(bytes.freeze()), + Ok(()) => { + bytes.put_u8(b'\n'); + Ok(bytes.freeze()) + } Err(e) => Err(Arc::new(e)), }; Self(result)