Looking to make alterations to a string using Typescript. The string is generated by the JSON.stringify() function.
I aim to eliminate the attributes "id", "lightStatus", and "value" from both "inputPort" and "outputPort" objects, only keeping their respective "id" property.
console.log(JSON.stringify(this.light));
// Output -> {"id":1,"name":"Light Switch","lightStatus":true,"inputPort":{"id":2,"value":0},"outputPort":{"id":2,"value":false},"resistance":100}
I attempted the following method but encountered issues with "inputPort.id" and "outputPort.id". Below is my attempt and the resultant output:
var savedLight = JSON.stringify(this.light, ["name", "inputPort.id", "outputPort.id", "resistance"]);
// Output -> {"name":"Light Switch","resistance":100}
The desired outcome should consist of the properties "name", "inputPort id", "outputPort id", and "resistance". Like so:
{"name":"Light Switch","inputPort": 2, "outputPort": 2, "resistance":100}
Could use some assistance in removing the unnecessary properties. Any help would be appreciated.