Many back ends return snake_case JSON while JavaScript code uses camelCase. Implement camelCaseKeys(value), which returns a new value where every key of every plain object, at any depth, has been converted to camelCase.
camelCaseKeys({
user_id: 7,
display_name: 'Ada',
recent_orders: [{ order_id: 1, line_items: [{ sku_code: 'X' }] }],
created_at: new Date(0),
});
// {
// userId: 7,
// displayName: 'Ada',
// recentOrders: [{ orderId: 1, lineItems: [{ skuCode: 'X' }] }],
// createdAt: <the same Date instance>,
// }
first_name becomes firstName, a_b_c becomes aBC, and double__under becomes doubleUnder._private and id_ are unchanged.already_Camel becomes alreadyCamel and HTTP_code becomes HTTPCode.Object.prototype or null) get new keys, and their values are processed recursively.null, Date, Map, class instances, functions) is returned as is, by reference.a_b and aB)?snakeCaseKeys, and is the round trip lossless?Spotted a mistake or a rights concern? Report an issue