dirty-pluck
v0.4.0
Published
Tiny library for plucking key values from JSON, but in a dirty way.
Readme
dirty-pluck
dirty-pluck is a tiny and straight-forward library for plucking JSON values. It's great for adapters of all sorts.
Installation
To add dirty-pluck to your project, you can use your favorite package manager.
npm install dirty-pluckyarn add dirty-pluckUsage
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]Licence
dirty-pluck is released under the MIT License.
Acknowledgements
This package is inspired by JSONata and JMESpath and fostered by the people at Primevise and Mintis
