Stack Exchange
Unexpected token o in JSON - node / API
When ran, I get an error saying:
undefined:1
[object Object]
^
SyntaxError: Unexpected token o in JSON at position 1
at JSON.parse ()
the code:
const express = require("express");
const app = express();
const https = require("https");
const bodyParser = require('body-parser')
app.use(bodyParser.urlencoded({extended: true}));
app.get("/",function (req,res) {

    res.sendFile(__dirname + "/public/index.html")
    
    app.use(express.static('public'));

})

app.post("/",function(req,res){

    const firstName = req.body.firstName;
    const lastName = req.body.lastName;
    const email = req.body.email;
    
    const data = {
        members:{
            email_address: email,
            status:"subscribed",
            merge_fields:{
                FNAME:firstName,
                LNAME:lastName
            }
        }
    }
    const jsonData = JSON.stringify(data);
const url = "https://us1.api.mailchimp.com/3.0/lists/";
const options = {
    method:"POST",
    auth:"sudolake:api_key"
}
const request = https.request(url, options, function(response){
    response.on("data",function(){
    console.log(JSON.parse(data));
})
   })


request.write(jsonData);
request.end();


})
app.listen(3000, function(){
    console.log("the server is up & running");

})


I know its probably something with the "const jsonData = JSON.stringify(data);" but I don't know what, its probably really stupid, thanks for any help

data is already an object in that console.log so you don't need to parse it again..  jsonData is that data in JSON, but you should just be able to use data directly.
