A slightly prettier version of what you have:
if let json = try? JSONSerialization.jsonObject(with: data, options: .mutableContainers),
let jsonData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) {
print(String(decoding: jsonData, as: UTF8.self))
} else {
print("json data malformed")
}