{"id":41337,"library":"json-key-formatter","title":"json-key-formatter","description":"A lightweight utility that replaces keys in a JSON object based on a provided mapping, supporting nested keys and arrays. Stable version 1.0.3, minimal dependencies. Differentiator: simple API focused solely on key renaming, unlike more comprehensive object transformation libraries.","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/batorovic/json-formatter","tags":["javascript","json-formatter","json","replace","value","formatter","utility"],"install":[{"cmd":"npm install json-key-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add json-key-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add json-key-formatter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export only; no default export exists.","wrong":"import transformKeysInObject from 'json-key-formatter'","symbol":"transformKeysInObject","correct":"import { transformKeysInObject } from 'json-key-formatter'"},{"note":"CommonJS destructuring required; the module does not assign to module.exports directly.","wrong":"const transformKeysInObject = require('json-key-formatter')","symbol":"transformKeysInObject","correct":"const { transformKeysInObject } = require('json-key-formatter')"},{"note":"TypeScript types may be available in future versions; check the package's types field.","wrong":"import { TransformKeysInObject } from 'json-key-formatter'","symbol":"TypeScript type","correct":"import type { TransformKeysInObject } from 'json-key-formatter'"}],"quickstart":{"code":"import { transformKeysInObject } from 'json-key-formatter';\n\nconst obj = {\n  _id: 1,\n  name: 'John Doe',\n  age: 30,\n  address: {\n    street: '123 Main Street',\n    city: 'Anytown',\n    state: 'CA',\n    zip: '12345',\n  },\n};\n\nconst keyMappings = {\n  _id: 'id',\n  name: 'fullName',\n  'address.city': 'location',\n};\n\nconst transformedObj = transformKeysInObject(obj, keyMappings);\n\nconsole.log(transformedObj);\n// Output:\n// {\n//   id: 1,\n//   fullName: 'John Doe',\n//   age: 30,\n//   address: {\n//     street: '123 Main Street',\n//     location: 'Anytown',\n//     state: 'CA',\n//     zip: '12345'\n//   }\n// }","lang":"javascript","description":"Shows how to rename keys in a nested object using a mapping with dotted path support."},"warnings":[{"fix":"Ensure array elements are not objects referencing the same memory if mutating.","message":"The function mutates the original object? No, it creates a new object, but arrays inside are not deeply cloned.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"There is no built-in escape; consider prefixing or replacing the dot with a placeholder before mapping.","message":"Key mappings with dots are treated as nested paths; to rename a key containing a dot, you must escape it or use a workaround.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure all mapping values are strings representing the new key names.","message":"Value type of the mapping object must be a string; non-string values are ignored or may cause errors.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.3':27 'api':32 'array':24 'base':15 'comprehens':40 'depend':29 'differenti':30 'focus':33 'formatt':4,47,51 'javascript':44 'json':2,13,46,48 'json-formatt':45 'json-key-formatt':1 'key':3,10,22,36 'librari':43 'lightweight':6 'map':19 'minim':28 'nest':21 'object':14,41 'provid':18 'renam':37 'replac':9,49 'simpl':31 'sole':34 'stabl':25 'support':20 'transform':42 'unlik':38 'util':7,52 'valu':50 'version':26","created_at":"2026-06-04T18:51:55.325637+00:00","updated_at":"2026-06-04T18:51:55.325637+00:00","problems":[{"fix":"Use `import { transformKeysInObject } from 'json-key-formatter'`","cause":"Importing as default instead of named export.","error":"TypeError: transformKeysInObject is not a function"},{"fix":"Ensure the first argument is a plain object or array.","cause":"Passing a non-object as the first argument.","error":"Cannot read properties of undefined (reading 'split')"},{"fix":"Provide a valid string for each mapping value.","cause":"Mapping value is null or undefined.","error":"Uncaught Error: Invalid key mapping"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/batorovic/json-formatter#readme","github":"https://github.com/batorovic/json-formatter","docs":null,"changelog":null,"pypi":null,"npm":"json-key-formatter","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}