Skip to content

JavaScript print object as JSON | Example code

  • by

If a JSON object and stored into a variable, then use JSON stringify() method to convert the print object as JSON in JavaScript.

Example print object as JSON in JavaScript

Simple example code.

<!DOCTYPE html>
<html>
<body>

  <script>

    var obj = {a: "A100", b: "B100" }
    var string = JSON.stringify(obj);

    console.log(obj)
    console.log(string)
    
  </script>

</body>
</html

Output:

JavaScript print object as JSON

Do comment if you have any doubts or suggestions on this JS Object print topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published. Required fields are marked *