pick
pick function picks the specified keys from a JSON object.
pick(object, keys, option?)Arguments
-
objecttype:
objectThe JSON object to pick keys from.
-
keystype:
string[]The keys to pick.
-
optiontype:
object-
arrayIndextype:
"dot" | "bracket"default:
"bracket"The index of array to pick.
e.g.
[ "a[0]" ]will pick to{ a: ["b"] }ifarrayIndexis"bracket", and[ "a.0" ]will pick to{ a: { 0: "b" } }ifarrayIndexis"dot".
-
Example
import { pick } from 'json-origami';
const user = { id: 1, name: 'John', age: 20, address: { street: '123 Main St', city: 'New York', state: 'NY', zip: '10001', },};
const picked = pick(user, ['id', 'name', 'address.street', 'address.city']);
/** * { * id: 1, * name: 'John', * address: { * street: '123 Main St', * city: 'New York', * }, * } */