object-nested-to-dot

1.0.3 • Public • Published

Nested to Dot Notation Object

Convert (2) levels nested object into dot notation object

Installation

npm i object-nested-to-dot

Usage

import {toDotNotation} from 'object-nested-to-dot';
 
console.log(toDotNotation({
    "a""TEST-A",
    "b""TEST-B",
    "c"{
        "childA""TEST CA",
        "childB""TEST CB"
    },
    "d"{
        "childA""TEST DA",
        "childB"{
            "grandChildA""TEST DBA"
        }
    }
}))
 
output: {
    "a""TEST-A",
    "b""TEST-B",
    "c.childA""TEST CA",
    "c.childB""TEST CB",
    "d.childA""TEST DA",
    "d.childB"{
        "grandChildA""TEST DBA"
    }
}

Disclaimer

This package only convert (2) levels nested object.

Extras

If you want to convert dot notation to nested object you can use this snippet with lodash

const toNested = (object) => {
    let newobj = {};
 
    Object.keys(object).map(key => {
        _.set(newobj, key, object[key])
    })
 
    return newobj;
}

Package Sidebar

Install

npm i object-nested-to-dot

Weekly Downloads

1

Version

1.0.3

License

MIT

Unpacked Size

2.13 kB

Total Files

3

Last publish

Collaborators

  • randjaegalvan