Create JSON Data for POST request in Express

JSON refers to the JavaScript Object Notation. Data can be transferred over HTTPS as JSON. For this process firstly we need to convert our normal text data to JSON format.

In this post we gonna check how to convert normal text to JSON data.

JSON is a combination of objects and arrays. So it allows us to send multiple data in a single JSON object.

eg:

   const data = {
        "email_address": email,
        "status": "subscribed",
        "name_fields": {
            "FNAME": fname,
            "LNAME": lname
        }
    }

    const jsonData = JSON.stringify(data); //turns data to string that is in format of JSON

In the above code, we are saving details of the user in a Javascript object called data. It includes email, names, status as key-value pairs.

Then we are using JSON.stringify() method for turning data to string that is in the format of JSON.

About the Author: smartcoder

You might like

Leave a Reply

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