rename-keys-recursive

1.0.9 • Public • Published

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.

Readme

Keywords

none

Package Sidebar

Install

npm i rename-keys-recursive

Weekly Downloads

8

Version

1.0.9

License

ISC

Unpacked Size

3.67 kB

Total Files

5

Last publish

Collaborators

  • jseanpar