Modify the names of the keys of objects and array recursively
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));
[
{
"code": 1,
"id": 1,
"attendance": [
{
"attendance": 58,
}
],
"asistencia_virtual": {
"porcentaje": 55
},
},
{
"id": 2,
"attendance": [
{
"attendance": 78,
}
],
"asistencia_virtual": {
"porcentaje": 55
},
},
];
Jose Rubilar
Copyright (c) 2016, Jose Rubilar. Released under the MIT license
Thanks to Team of PDV for encouraging me and supporting me to carry out this development.