Global config options / defaults
mikejpeters opened this issue · comments
I brought this up in #18 but I think I failed to explain myself clearly (or else have misunderstood the replies), and it's more appropriate as it's own issue.
I think it would be very useful to be able to set global options / defaults.
I have many different template configs for different JSON structures I want to transform, but I want to never ignore null or undefined attributes. Currently I believe I have to set {ignoreEmpty: false}
in every template config, at every level. It would be great to be able to do something like:
json2json.defaults.ignoreEmpty = false;
or
json2json.setDefaults({ignoreEmpty: false});
so that whenever I call new json2json.ObjectTemplate(config)
the resulting config will use those defaults at every level.
I would be happy to create a PR for this feature if you agree it would be useful. (Currently I think the only real application is for the ignoreEmpty
option, but maybe it's best to implement a general solution like above for flexibility and in case more relevant config options are included in the future.)
I would use this, nice idea!
@mikejpeters this seems to make sense. Did you work on an implementation?
@mikejpeters @lpww this is merged and will be in v0.2.6