1.0.3 • Published 4 years ago

object-nested-to-dot v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

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;
}