I want to change string to variable, please some one help me.
this is a string >> {"method":"setValue","params":{"cmd_Motor":true}}
I wan to change like this:
I want to change string to variable, please some one help me.
this is a string >> {"method":"setValue","params":{"cmd_Motor":true}}
I wan to change like this:
Use JSON.parse()
const input = '{"method":"setValue","params":{"cmd_Motor":true}}';
const result = JSON.parse(input);
I am not sure if I understood your question, but you can convert a string to a JSON object and you can also convert a JSON object to a string:
converting from string to json
const myString = '{"method":"setValue","params":{"cmd_Motor":true}}';
const myJson = JSON.parse(myString);
console.log(myJson.method) // setValue
console.log(myJson.params.cmd_Motor) // true
converting from json to string
const myJson = { method: 'setValue', params: { cmd_Motor: true } };
const myString = JSON.stringify(myJson);
console.log(myString);