Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
transformKeysInObject
✓ import { transformKeysInObject } from 'json-key-formatter'
✗ import transformKeysInObject from 'json-key-formatter'
Named export only; no default export exists.
transformKeysInObject
✓ const { transformKeysInObject } = require('json-key-formatter')
✗ const transformKeysInObject = require('json-key-formatter')
CommonJS destructuring required; the module does not assign to module.exports directly.
TypeScript type
✓ import type { TransformKeysInObject } from 'json-key-formatter'
✗ import { TransformKeysInObject } from 'json-key-formatter'
TypeScript types may be available in future versions; check the package's types field.
Shows how to rename keys in a nested object using a mapping with dotted path support.
import { transformKeysInObject } from 'json-key-formatter';
const obj = {
_id: 1,
name: 'John Doe',
age: 30,
address: {
street: '123 Main Street',
city: 'Anytown',
state: 'CA',
zip: '12345',
},
};
const keyMappings = {
_id: 'id',
name: 'fullName',
'address.city': 'location',
};
const transformedObj = transformKeysInObject(obj, keyMappings);
console.log(transformedObj);
// Output:
// {
// id: 1,
// fullName: 'John Doe',
// age: 30,
// address: {
// street: '123 Main Street',
// location: 'Anytown',
// state: 'CA',
// zip: '12345'
// }
// }
Errors
Common errors & fixes
TypeError: transformKeysInObject is not a function
Importing as default instead of named export.
fixUse `import { transformKeysInObject } from 'json-key-formatter'` Cannot read properties of undefined (reading 'split')
Passing a non-object as the first argument.
fixEnsure the first argument is a plain object or array.
Uncaught Error: Invalid key mapping
Mapping value is null or undefined.
fixProvide a valid string for each mapping value.
Audit
Dependencies
No dependency data recorded yet.