Show Output
<!DOCTYPE html> <html lang="en"> <head> <title>JavaScript Pretty Print JSON Object</title> </head> <body> <script> // Sample object var obj = {"name": "Peter", "age": 22, "country": "United States"}; // Pretty printing var str = JSON.stringify(obj, null, 4); // spacing level = 4 document.write("<pre>" + str + "</pre>"); </script> </body> </html>