There are a few examples of this around the forum.
For example, you could easily adapt this: Help converting string to key/value object - #2 by Steve-Mcl
E.g...
const lines = msg.payload.split("\n");
let result = {};
for (let i = 0; i < lines.length ; i++) {
const line = lines[i].trim();
if(!line) continue;
let parts = line.split(":");
if(parts.length != 2) continue;
let key = parts[0].trim();
let val = parts[1].trim();
if(isNumeric(val)) val = Number(val)
result[key] = val;
}
msg.payload = result;
return msg;
function isNumeric(n) {
return !isNaN(parseFloat(n)) && isFinite(n);
}
Untested - may need tweaking