I have json data comes server side.
In case I use the next code I get not pretty printed one line string:
print(String(bytes: jsonData, encoding: String.Encoding.utf8))
To make it pretty printed I use the next code:
if let json = try? JSONSerialization.jsonObject(with: jsonData, options: .mutableContainers) {
if let prettyPrintedData = try? JSONSerialization.data(withJSONObject: json, options: .prettyPrinted) {
print(String(bytes: prettyPrintedData, encoding: String.Encoding.utf8) ?? "NIL")
}
}
But seems that it isn't the best way.
So does anybody know how to pretty print incoming jsonData to print it?