Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 358 Vote(s) - 3.61 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Pretty print JSON output of Spring Boot Actuator endpoints

#11
Actually I wanted to do the same. But then I asked: why? To debug my service better which comes with a small performance penalty.

Just use a browser extension, [like this one][1] :) to get a view like this one

[![enter image description here][2]][2]

[1]:

[To see links please register here]

[2]:
Reply

#12
Instead of using `curl` I like to use [`httpie`][1] as a http command line client:

`http

[To see links please register here]

`

This would already format and syntax highlight the json response without having to pipe the output into another command. Also the command syntax is a bit more human friendly.


[1]:

[To see links please register here]

Reply

#13
If you're using **gson** serialization with Spring, then none of the other answers will work for you. You'll have to use this configuration option:

`spring.gson.pretty-printing=true`

Confirmed working with Spring Boot as of version `2.0.3.Release`.
Reply

#14
this not working

`spring.jackson.serialization.INDENT_OUTPUT=true`

this is working `spring.jackson.serialization.indent-output=true`
Reply

#15
In case somebody with Spring Boot 2 (2.1.1 in my case) stumbles over this question as I did: We faced the same problem, and none of the answers helped for 2.1.1.

So what we did was to replace the existing endpoint (`health` in our case) with a new one. I described it at the end of [this answer][1]. And yes, this limits our solution to this single endpoint, but on the other hand it has the advantage of being able to format the output in any way you want - including pretty print JSON, but also output styled HTML if requested (by a service technician in a browser in our case). Note the `produces` attribute of `@ReadOperation` to achieve that.


[1]:

[To see links please register here]

Reply

#16
This is the latest as of 12/27/2022. The below works.
-For application.yml config.

spring:
jackson:
serialization:
indent-output: true

But the above config won't work, if you implement WebMvcConfigurer class. In that case, override like below to make it work.

@Override
public void extendMessageConverters( List<HttpMessageConverter<?>> converters ) {
for ( HttpMessageConverter<?> converter : converters ) {
if ( converter instanceof MappingJackson2HttpMessageConverter) {
MappingJackson2HttpMessageConverter jacksonConverter = (MappingJackson2HttpMessageConverter) converter;
jacksonConverter.setPrettyPrint( true );
}
}
}

Reply

#17
Spring Boot Actuator uses its own isolated `ObjectMapper` instance by default in which `indent-output` is disabled. To enable pretty-print of actuator output, you must set the following properties:

```
spring.jackson.serialization.indent-output=true
management.endpoints.jackson.isolated-object-mapper=false
```
Reply



Forum Jump:


Users browsing this thread:
2 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through