Answer the question
In order to leave comments, you need to log in
Asynchronous JSON to JSON converter for NodeJS?
Let's say some JSON comes from the server. It is necessary to reformat it according to certain rules in order to put it in the database or continue to work as an object in the application. Libraries for converting JSON to JSON in bulk. The syntax for describing the rules is for every taste. But I can’t find one among them that would support asynchronous conversion rules (at least on callbacks, at least on promises, it doesn’t matter).
convert(jsonFromServer, {
dstField1: function(jsonFromServer, callback) {
DB.lookupField(jsonFromServer.srcField1, function(err, val) {
if (err) { return callback(err); }
callback(null, val);
});
}
});
convert(jsonFromServer, {
dstField1: (jsonFromServer) => DB.lookupField(jsonFromServer.srcField1)
.then(val => val.toUpperCase())
});
Answer the question
In order to leave comments, you need to log in
Well, everything ended up writing my own lib, unfortunately: https://www.npmjs.com/package/async-mapper
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question