Can I use LoDash to map a large json object (from a REST service) to a smaller object?
I am getting a list of tweets (from a REST service) which is a really big list of many properties, but I am only interested in a few properties in each item of the returned collection.
What's the best way to map this to a smaller object? Will Lodash help here?
Will I just iterate over it and create a lot of new object?
+3
source to share
2 answers
Assuming you've already created an array of large tweet objects from your JSON (String), there is actually an underscore / lodash function to create objects with subsets of properties. Thank you after _. Select .
Basically, you would do something along the lines of:
var importantParams = ["id", "user", "text", "created_at"];
var smallerObjArray = _.map(largerObjArray, function(largeObj){
return _.pick(largeObj, importantParams);
});
+3
source to share