I want to mould a JSON object into the following required format:
Here is the,
Input data:
let data = {
phone_number: phone.phoneInputValue,
platform: 'app',
device_id: uniqueId,
device_type: 'app',
channel: 'sms',
};
and this I want to generate as Output:
{"phone_number"=>"+919878249741",
"platform"=>"app", "device_id"=>"123456", "device_type"=>"abcde",
"channel"=>"sms"}
Achieved (the order is different) same I want to do for object keys currently its working on values only:
"channel=>"sms",device_id=>"a6335b3b84eaf86b",device_type=>"app",phone_number=>"+916555558998",platform=>"app"
Method used:
const formattedString = JSON.stringify(data)
.replace(/"([^"]+)":/g, '$1=>')
.replace(/[{}]/g, '');
Any help is highly appreciated! Thanks