Is there a way to implement functions within a JavaScript file (configuration for backend server) that execute before parsing the data to JSON?
For example:
config.js
module.exports = {
structure_layout: {
BUILDING: "BUILDING",
FLOOR: "FLOOR",
ROOM: "ROOM",
},
structure: {
HOUSE: {
type: function () {
return this.structure_layout.BUILDING
}
},
FLAT: {
type: function () {
return this.structure_layout.FLOOR
}
},
}
};
The expected output in config.json
after parsing should be:
{
"structure_layout": {
"BUILDING": "BUILDING",
"FLOOR": "FLOOR",
"ROOM": "ROOM"
},
"structure": {
"HOUSE": {
"type": "BUILDING"
},
"FLAT": {
"type": "FLOOR"
}
}
}
Currently, when using JSON.stringify
, I am not getting the desired results with empty type
attributes.
Are there any alternative methods to define a JavaScript version of the config without relying on functions to achieve the same outcome?