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.
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.
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:
Or in YAML:
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:
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:
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
jqor 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
- Problems using Maven and SSL behind proxy
- Produce balanced mini batch with Dataset API
- Producer throughput with varying acks=0,1,-1
- Programmatically make Amazon purchase?
- Pretty printing JSON from Jackson 2.2's ObjectMapper
- Prevent Application / CommandLineRunner classes from executing during JUnit testing
- Prevent stack trace logging for custom exception in Spring Boot application
- Preventing Exceptions from 3rd party component from crashing the entire application

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack 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.