json-sculpt
Version:
JSON Sculpt is a utility library designed to transform or "sculpt" JSON objects into your desired shape.
28 lines (27 loc) • 781 B
TypeScript
import { JsonObject } from "../types";
/**
* Searches for the first object that matches the provided matcher within a JSON structure
*
* @param json - JSON object within which to perform the search
* @param matcher - JSON object used to match objects within the provided JSON structure
* @returns The first matched JSON object, or undefined if no match is found
*
* @example
* const data = {
* name: "Brennan",
* age: 30,
* child: {
* name: "Daisy",
* age: 5,
* },
* };
*
* const matcher = {
* name: "Daisy",
* };
*
* const foundObject = findObjectInJson(data, matcher);
*
* console.log(foundObject); // { name: "Daisy", age: 5 }
*/
export declare const findObjectInJson: (json: JsonObject, matcher: JsonObject) => JsonObject | undefined;