jsonkeyfinder
v1.0.2
Published
Key finder from very deep json
Readme
jsonkeyfinder
Description
jsonkeyfinder is a lightweight npm package that provides a function to find the value of any key from deep levels of JSON. It's useful for traversing complex JSON structures and retrieving specific values efficiently.
Installation
You can install jsonkeyfinder via npm:
npm install jsonkeyfinderUsage
import { findValueByKey } from 'jsonkeyfinder';
const jsonObject = {
"foo": {
"bar": {
"baz": "value"
}
}
};
const value = findValueByKey(jsonObject, 'baz');
console.log(value); // Output: "value"API
findValueByKey(json: JsonObject, key: string): any
json: The JSON object to search within.key: The key to search for within the JSON object.- Returns the value associated with the specified key. Returns
undefinedif the key is not found.
Example
import { findValueByKey } from 'jsonkeyfinder';
const jsonObject = {
"name": "John Doe",
"age": 30,
"address": {
"city": "New York",
"zip": 10001
}
};
const age = findValueByKey(jsonObject, 'age');
console.log(age); // Output: 30License
This package is licensed under the MIT License. See the LICENSE file for details.
Author
Created by abhijeet_vadera.
