Last Updated : Jan 1, 2023
- With the help of the JSON.stringify() method
- With the help of the JSON.parse() method
In this article, we are going to show conversion with help of a JSON.stringify() whereas in the next article we will understand another method.
Below, we will show you an example with the help of codes. Let us understand the example given for quickly learning.
- In previous tutorials, we already many times create a full code example in which we first create an HTML form with its basic structure. We use HTML, head, title, body, and script tags inside that structure.
- In the first example, we see that a paragraph tag is created with an id. After that, we create our Script tag. A script tag is paired tag and is used to write scripts in between the opening and closing tag.
- Now, after the creation of the object we show you the object that was created with the help of the console, and after that, we use JSON.stringify() to convert the object to JSON, So after successful conversion, we store the result inside a variable and just again console this variable to display result. So, after seeing the console you see that our JS object was successfully converted into JSON with the help of stringifying.