the value of props.record.DataUpdate.draft
{"FirstName": "This is my firstname","MiddleName": "This is my middlename","LastName": "this is my lastname"}
let newData = JSON.parse(props.record.DataUpdate.draft)
console.log(newData)
{
"FirstName": "This is my firstname",
"MiddleName": "This is my middlename",
"LastName": "this is my lastname"
}
this is my database looks like
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
tableNameToBeUpdated: {
type: Sequelize.STRING,
},
tableIdToBeUpdated: {
type: Sequelize.STRING,
},
draft: {
type: Sequelize.JSON,
},
CreatedDate: {
type: Sequelize.DATE,
},
LastUpdateDate: {
type: Sequelize.DATE,
},
status: {
type: Sequelize.STRING,
},
what I want here is to get the label (Fistname,Lastname,Middlename) with there perspective value,
note the label can be change it depends on the string that saves on draft column
how to achieve that?
CodePudding user response:
Something like that:
const jsonString = {"FirstName": "This is my firstname","MiddleName": "This is my middlename","LastName": "this is my lastname"}
for (var key in jsonString) {
console.log(key " -> " jsonString[key]);
}
This gives me the Output:
'FirstName -> This is my firstname'
'MiddleName -> This is my middlename'
'LastName -> this is my lastname'
Edit: Ok i took the example form your post (without the single quotes). Then just do what you posted and then use the for loop:
const jsonString = '{"FirstName": "This is my firstname","MiddleName": "This is my middlename","LastName": "this is my lastname"}'
const jsonObject = JSON.parse(jsonString)
for (var key in jsonObject) {
console.log(key " -> " jsonObject[key]);
}