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