1.0.9 • Published 2 years ago
rename-keys-recursive v1.0.9
rename-keys-recursive
Modify the names of the keys of objects and array recursively
Usage
const { renameKeysRecursive } = require('rename-keys-recursive');
let o = [
{
"codigo": 1,
"id": 1,
"asistencia": [
{
"asistencia": 58,
}
],
"asistencia_virtual": {
"porcentaje": 55
},
},
{
"id": 2,
"asistencia": [
{
"asistencia": 78,
}
],
"asistencia_virtual": {
"porcentaje": 55
},
},
];
//replace key asistencia for attendance, codigo for key code
global.config = {
asistencia: 'attendance',
codigo: 'code'
}
const resp = renameKeysRecursive(o);
console.log(JSON.stringify(resp));
Return output object
[
{
"code": 1,
"id": 1,
"attendance": [
{
"attendance": 58,
}
],
"asistencia_virtual": {
"porcentaje": 55
},
},
{
"id": 2,
"attendance": [
{
"attendance": 78,
}
],
"asistencia_virtual": {
"porcentaje": 55
},
},
];
Authors
Jose Rubilar
Licence
Copyright (c) 2016, Jose Rubilar. Released under the MIT license
Acknowledgments
Thanks to Team of PDV for encouraging me and supporting me to carry out this development.