A
A
anotherpit2017-01-25 13:43:58
JavaScript
anotherpit, 2017-01-25 13:43:58

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())
});

If you know one, please tell me. Once to write your own.
Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
anotherpit, 2017-02-07
@anotherpit

Well, everything ended up writing my own lib, unfortunately: https://www.npmjs.com/package/async-mapper

E
emp1re, 2017-01-25
@emp1re

https://github.com/phretaddin/schemapack

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question