Spring Boot
JSON
Actuator
Pretty Print
API Debugging

Pretty print JSON output of Spring Boot Actuator endpoints

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

Introduction

Actuator endpoints already return JSON, but the default response is usually compact rather than human-friendly. If the goal is debugging, the best solution is often to pretty-print on the client side instead of changing server behavior globally. Spring Boot can also indent JSON on the server, but that affects more than just Actuator and is usually not the first choice for production systems.

The Simplest Option: Pretty-Print on the Client

If you are inspecting Actuator responses from the command line, pipe the output through a JSON formatter such as jq.

bash
curl -s http://localhost:8080/actuator/health | jq

That is often the cleanest answer because:

  • the server stays unchanged
  • the formatting happens only when you need it
  • production responses remain compact

This works well for endpoints such as:

  • '/actuator/health'
  • '/actuator/info'
  • '/actuator/metrics'

For many debugging workflows, client-side formatting is enough.

Server-Side Indentation with Jackson

If you really want Spring Boot to return indented JSON, enable Jackson's indentation setting in configuration:

properties
spring.jackson.serialization.indent_output=true

Or in YAML:

yaml
1spring:
2  jackson:
3    serialization:
4      indent_output: true

Once enabled, JSON responses produced through Jackson become easier to read directly in a browser or raw HTTP client.

The important catch is that this is not Actuator-specific. It changes JSON serialization more broadly across the application.

Understand the Scope of the Setting

That global scope matters. If your application also serves:

  • normal REST APIs
  • admin endpoints
  • internal JSON responses

then those responses may be indented too. Pretty JSON is useful for humans, but it increases response size slightly and is usually unnecessary for machine clients.

That is why many teams keep server responses compact and pretty-print only in tools such as:

  • 'jq'
  • Postman
  • browser JSON viewers

A Controller Example for Context

Here is a simple controller to illustrate the effect:

java
1import java.util.Map;
2import org.springframework.web.bind.annotation.GetMapping;
3import org.springframework.web.bind.annotation.RestController;
4
5@RestController
6public class DemoController {
7
8    @GetMapping("/demo")
9    public Map<String, Object> demo() {
10        return Map.of("status", "ok", "count", 3);
11    }
12}

With indentation enabled, this endpoint and Actuator endpoints both become more readable in raw output. Without it, the JSON stays compact.

For Logging, Format Separately

Pretty-printing HTTP responses is not the same as pretty-printing JSON for logs. If you need readable JSON in logs, format it where you log it rather than depending on the HTTP serialization setting.

For example, using Jackson directly:

java
1import com.fasterxml.jackson.databind.ObjectMapper;
2
3ObjectMapper mapper = new ObjectMapper();
4String pretty = mapper.writerWithDefaultPrettyPrinter()
5    .writeValueAsString(Map.of("status", "ok", "count", 3));
6
7System.out.println(pretty);

This distinction matters because operational logging and HTTP response formatting are different concerns.

Actuator Security Still Matters

Pretty printing improves readability, not safety. Actuator endpoints can expose sensitive operational information depending on which endpoints are enabled and how access is configured. Formatting them nicely does not change that risk.

So if you enable or inspect Actuator output, also think about:

  • which endpoints are exposed
  • who can access them
  • whether production exposure is appropriate

That is more important than indentation itself.

Common Pitfalls

  • Turning on global JSON indentation when the real need was only nicer terminal output.
  • Assuming the indentation setting affects only Actuator endpoints.
  • Confusing pretty-printed HTTP responses with pretty-printed logs.
  • Ignoring Actuator endpoint exposure and security while focusing on formatting.
  • Adding server-side formatting in production when jq or another client tool would have been enough.

Summary

  • The easiest way to pretty-print Actuator JSON is often curl ... | jq.
  • Spring Boot can indent JSON server-side with Jackson, but that affects more than just Actuator.
  • Client-side formatting is usually better for debugging and operations.
  • Keep HTTP response formatting separate from log formatting concerns.
  • Readability is helpful, but Actuator exposure and security matter more than indentation.

Related reading
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

System Design practice on Codemia

Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.

Practice system design

All Rights Reserved.