If you’ve ever experienced the headaches with reformatting JSON, I’m here to help. Today, I would like to introduce Distill: a small library that removes impurities from a JSON schema and will improve how you create APIs.
As you can see, simply require the distill module, then pass it an object (or array of objects). It allows you to chain methods for plucking fields or embedding specific keys from arrays that it might encounter. Distill is simple, but it gets the job done. In fact, this post is probably overkill, but I’m sharing this snippet mostly for my RSS readers. If you’ve ever wrote complex map statements with Underscore or Lodash, this dramatically cleans up your code. In my benchmarks, it doesn’t introduce noticeable overhead either.
Photo credit: Josh Koontz - used under a BY-NC license.