Currently, I am developing a small module for Angular and I have encountered an issue regarding the condition where I verify my JSON.parsed data.
read(): Position|null {
try {
...
let parsedData = JSON.parse(data);
if (parsedData && parsedData.x && parsedData.y)
return new Position(parsedData.x, parsedData.y);
} catch (e) {
...
}
return null;
}
I find this solution to be suboptimal as it would require me to check for each property if there are more properties in the object that I had previously stringified. Additionally, I am unsure about how to handle cases when the parsed data is null
. Are there any alternative solutions for validating the stringified data? Thank you