-1

I have the following config in json format:

var obj = {"PUSH" : {"title" : "Medicines Packed - Bill Value    {amount}", "body" : "We have packed your medicines. Your final bill value is Rs {amount} . We will shortly update you on the delivery boy details."}};

var myJSON = JSON.stringify(obj);
myJSON.replace("{amount}", "100");

I basically have {amount} as a placeholder which I'm trying to replace in Node.js in the above way. But the placeholders remain as it is and no replacement takes place. What's the correct way to do this ?

ellipsis
  • 12,049
  • 2
  • 17
  • 33
Nilesh Guria
  • 139
  • 2
  • 9
  • var obj = {"PUSH" : {"title" : "Medicines Packed - Bill Value {amount}", "body" : "We have packed your medicines. Your final bill value is Rs {amount} . We will shortly update you on the delivery boy details."}}; var myJSON = JSON.stringify(obj); var replacedString= myJSON.replace(new RegExp('{amount}', 'g'), 100) – arunmmanoharan Feb 26 '19 at 19:11

1 Answers1

0

You can use split and join

var obj = {
  "PUSH": {
    "title": "Medicines Packed - Bill Value    {amount}",
    "body": "We have packed your medicines. Your final bill value is Rs {amount} . We will shortly update you on the delivery boy details."
  }
};
console.log(JSON.stringify(obj).split("{amount}").join("100"))
ellipsis
  • 12,049
  • 2
  • 17
  • 33