dirty-pluck
is a tiny and straight-forward library for plucking JSON values. It's great for adapters of all sorts.
To add dirty-pluck
to your project, you can use your favorite package manager.
npm install dirty-pluck
yarn add dirty-pluck
dirty-pluck
is opinionated and not meant to be a query language. However, it's as simple as it gets if you want to pluck whatever values that get in the way.
import pluck from "dirty-pluck";
const data = {
restaurant: {
title: "The Best Restaurant",
reviews: [{ rating: 8.5 }, { rating: 2.7 }, { rating: 9.1 }],
},
};
pluck(data, "restaurant.title");
// => ["The Best Restaurant"]
pluck(data, "restaurant.reviews");
// => [{ rating: 8.5 }, { rating: 2.7 }, { rating: 9.1 }]
pluck(data, "restaurant.reviews.rating");
// => [8.5, 2.7, 9.1]
dirty-pluck
is released under the MIT License.
This package is inspired by JSONata and JMESpath and fostered by the people at Primevise and Mintis