Im working with nodejs for backend. And im asking myself why should I use config.json, data.json etc. Why not to use js object and make deepFreeze to it? Whats the benefits of json?
Like:
const config = {
serviceName: test,
port: 4050,
};
const deepFreeze = obj => {
Object.keys(obj).forEach(prop => {
if (typeof obj[prop] === 'object' && !Object.isFrozen(obj[prop]))
deepFreeze(obj[prop]);
});
return Object.freeze(obj);
};
deepFreeze(config);
json is a text format for representing arrays and objects easily.
The interest of json is that it is independent of a language.
You can read or write JSON from javascript, but also from other languages.
Moreover, during exchanges between a client and a server, it is easy to use it to transport data.