Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ofarukcaki/jsonfind
Finds and exports all values of given key from an unknown structured json object.
https://github.com/ofarukcaki/jsonfind
Last synced: about 1 month ago
JSON representation
Finds and exports all values of given key from an unknown structured json object.
- Host: GitHub
- URL: https://github.com/ofarukcaki/jsonfind
- Owner: ofarukcaki
- Created: 2019-05-12T16:18:56.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2019-06-11T07:49:34.000Z (over 5 years ago)
- Last Synced: 2024-11-23T01:27:13.692Z (2 months ago)
- Language: JavaScript
- Size: 6.84 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# json-nested-find
Finds and exports all values of given key from an unknown structured json object, array or array of objects.
- Recursive lookup
- No aditional dependency
- Small size(4kb)## Install
```
npm i json-nested-find@latest
```## Basic Usage
```javascript
const jsonfind = require("json-nested-find");// example json object
let sample = [
{ author: "Jack London", book: "The Call of the Wild", year: 1903 },
{ author: "Tolstoy", book: "War and Peace" },
{ author: "Dostoevsky", book: "Crime and Punishment" },
{ author: "Dostoevsky", book: "The Brothers Karamazov" },
{
nested: {
another: [{ author: "M.Kemal Atatürk", book: "Nutuk", year: 1927 }]
}
}
];// call jsonfind's All function (the only function of this dependency right now)
// 2nd parameter is used for a key to search, "author" in this example.// outputs (return a Set)
console.log(jsonfind.All(sample, "author"));
// Set { 'Jack London', 'Tolstoy', 'Dostoevsky', 'M.Kemal Atatürk' }console.log(jsonfind.All(sample, "year"));
// Set { 1903, 1927 }
```