Hi Peter,
I have done something similar for SOAP responses (XML) using a Java action. You should be able to work out the same for JSON (for example see https://stackoverflow.com/questions/4105795/pretty-print-json-in-java)
In addition, if your purpose is to display the JSON within a Mendix app you could also try the JSON Viewer/Editor widget: https://appstore.home.mendix.com/link/app/105713/
Cheers,