I have changed data in string format where it was like [object object] but I want to change the string object into json object I tried json.parse but it not changing into json object
can you please suggest me where I am doing wrong and how to fix this
try {
var timekeep = await Orders.findAndCountAll({
where: {
cid: orders_info.cid,
},
order: [
['id', 'DESC']
],
limit: 1,
raw: true,
});
var cont1 = JSON.stringify(timekeep.rows[0]);
var obj = JSON.parse(cont1);
} catch (err) {
console.log(err)
}
console.log('org data' + timekeep)
console.log('data as string' + cont1);
// now when I am trying to print
console.log('data as json' + obj);
the output of the console.logs
org data [object Object]
data as sttring{"id":4006,"mid":1,"cid":41,"wid":7138,"oid":null,"status":null,"options":null,"starttime":"2018-08-15T06:08:55.000Z","duration":null,"ordertotal":50,"counter":null,"closetime":null}
data as json [object object]
var obj = JSON.parse(obj);=>var obj = JSON.parse(cont1);console.log(obj);- It's already an object. When you doconsole.log("something" + object)it automatically turns the object into a string and appends it to the string you're logging. If you want to log with a bit of text to tell you what you've logged then use a comma like this...console.log("data as object", obj);console.log(obj)it's already a json object.