Currently, I am retrieving a JSON object from a database and mapping it to another JSON object. However, due to limitations in the column names of my database, I am required to manually assign some values. Below is a snippet of the model:
...
InvoiceLineBaseQuantityUnitCode: string;
InvoiceLineSubTotalTaxCategoryID: string;
InvoiceSubTotalTaxCategoryPercent: string;
InvoiceTaxTotal: string;
"InvoiceTotal/InvoicePayableAmount": string;
InvoiceLineID: string;
WST: string;
VERFAHREN: string;
BxLxH: string;
GEW: string;
HINWEISE: string;
ilbquc: string;
ilsttci: string;
isttcp: string;
it: string;
In order to reassign the values correctly and remove the temporary ones, I do the following:
item.InvoiceLineBaseQuantityUnitCode = item.ilbquc;
item.InvoiceLineSubTotalTaxCategoryID = item.ilsttci;
item.InvoiceSubTotalTaxCategoryPercent = item.isttcp;
item['InvoiceTotal/InvoicePayableAmount'] = item.it;
delete item.ilbquc;
delete item.ilsttci;
delete item.isttcp;
delete item.it;
However, this process appends the keys at the end of the object instead of "overwriting" the existing ones. The endpoint where we need to send the object requires a specific key order similar to the model.
Is there a way to re-map this object to follow the class structure for correct key ordering? Or perhaps, is there a method to sort by class property?
Thank you in advance.