Golang alternative to Pythons pprint.pformat

I am rewriting a Python CLI in Golang due to a network effect I want to utilize. One of the challenges I am facing is that I can’t seem to find a replacement for Pythons pprint.pformat.

I am aware of go-spew but the project seems to be dead as it doesn’t even have a go.mod file.

I am aware of the fmt.Printf but rebuilding the same user experience with that will be quite more work than I was expecting.

If you want to output it as pretty JSON you can always use MarshalIndent:

See this StackOverflow answer for more details. If you want to be able to have more control, you’d have to use reflection (similar to how that package you linked is doing). This package also looks interesting:

Thank you for your recommendations! I think that pretty much satisfies my need and as such this topic can be seen as solved.

I was aware of the JSON encoder but I think is a different use-case than pretty printing as the encoder converts the output quite a bit. With pretty the internal representation of the object is kept.