Struggling to convert data types to numbers using JSON.parse and the Reviver function. I've experimented with different options and examples, but can't seem to figure out where I'm going wrong. The Typescript interface I'm working with has defined types, but the incoming JSON file uses "" for all values.
My only requirement is to change strings to numbers, nothing else.
Here's an example of the JSON input ->
{"sub_type": "0", "year": "2023", "peak": "N"}
Expected output:
{"sub_type": 0, "year": 2023, "peak": "N"}
I have attempted the following code snippet to achieve this:
let cards: Array<Card> = pt_cards['data'];
let tstCard: Card = JSON.parse(JSON.stringify(cards[0]), (key, value) => {
if(!isNaN(value)) {
return(key: value);
}
return value;
});
Should I consider replacing the current Interface declaration instead?