I want to create a json Object in Nodejs. I am fairly new to Nodejs and Javascript. Below is the json format.
{
"Req": {
"addr": ["teleNumber:021544"],
"sendAddre": "teleNumber:347889",
"outSMSBinaryMessage": {"message": "asdfa12547"},
"validityPeriod": "10"
}
}
CodePudding user response:
JSON is JavaScript object notation. What you have added is a JS object. If you want to create a JSON string, then use JSON.stringify(yourObject)
. If we want to parse that JSON string, use JSON.parse(yourObjectStringified)
.
CodePudding user response:
Are you looking to create interfaces or classes? To get started, you can use online tools to convert JSON into Typescript interfaces.
https://jsonformatter.org/json-to-typescript
export interface Welcome10 {
Req: Req;
}
export interface Req {
addr: string[];
sendAddre: string;
outSMSBinaryMessage: OutSMSBinaryMessage;
validityPeriod: string;
}
export interface OutSMSBinaryMessage {
message: string;
}