1.0.9 • Published 2 years ago

rename-keys-recursive v1.0.9

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

rename-keys-recursive NPM version

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.

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago