JSPM

complex-json

0.1.3
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 11
  • Score
    100M100P100Q39207F
  • License MIT

Access the deep objects inside an object with ease.

Package Exports

  • complex-json

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (complex-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Welcome to complex-json 👋

Version Documentation License: MIT Twitter: vigneshkv23

Access the deep objects inside an object with ease.

Install

npm install complex-json -save

Usage

var complexJson = require('complex-json');

GET:

returns value
var json = {
        "a": {
            "b": "value"
            }
        }
var key = 'b';
var res = complexJson.get(json, key)

var json = {
    "a": {
        "b": {
            "c": {
                "d": [
                    {
                        "e": {
                            "f": "value"
                        },
                        "e1": [
                            {
                                "f": "value"
                            }
                        ]
                    }]
            }
        }
    }
}

note:parentObj is non-mandatory, if key has same name is other object parentObj
var keys = "f";
var parentObj = "e";
var res = complexJson.get(json, keys, parentObj);

SET

var json = {
   "a": {
       "b": "value"
   }
}

var key = 'b';
var valueToReplace = 'newValue';
var res = complexJson.set(json, key, valueToReplace);

var json = {
   "a": {
       "b": {
           "c": {
               "d": [
                   {
                       "e": {
                           "f": "value"
                       },
                       "e1": [
                           {
                               "f1": "value"
                           }
                       ]
                   }]
           }
       }
   }
}

// set single value
note: parentObj is non-mandatory, if key has same name is other object

var keys = "f";
var valueToReplace = "sucess"
var parentObj = "e";

var res = complexJson.set(json, keys, valueToReplace, parentObj);

// set multiple value at a time
// array length of keys, valueToReplace, parentObj should be same
// all the params are mandatory incase of setting multiple values at a time

var keys = ["f", "f1"];
var valueToReplace = ["new f value", "new f1 value"]
var parentObj = ["e", "e1"];
var res = complexJson.set(json, keys, valueToReplace, parentObj);

DELETE

returns modified JSON

var json = {
   "a": {
       "b": "value",
       "c": "value",
   }
}

var key = 'b';
var res = complexJson.del(json, key);

var json = {
   "a": {
       "b": {
           "c": {
               "d": [
                   {
                       "e": {
                           "f": "value",
                           "g": "value"
                       },
                       "e1": [
                           {
                               "f1": "value"
                           }
                       ]
                   }]
           }
       }
   }
}

// del single value
note:parentObj is non-mandatory, if key has same name is other object parentObj
var keys = "f";
var parentObj = "e";
var res = complexJson.del(json, keys, parentObj);

HAS

returns boolean

var json = {
   "a": {
       "b": "value"
   }
}

var key = 'b';
var res = complexJson.has(json, key);

var json = {
   "a": {
       "b": {
           "c": {
               "d": [
                   {
                       "e": {
                           "f": "value"
                       },
                       "e1": [
                           {
                               "f1": "value"
                           }
                       ]
                   }]
           }
       }
   }
}

note: parentObj is non-mandatory, if key has same name is other object
var keys = "f";
var parentObj = "e";
var res = complexJson.has(json, keys, parentObj);

GETPATH

returns path array 

var json = {
   "a": {
       "b": "value"
   }
}

var key = 'b';
var res = complexJson.getPath(json, key);

var json = {
   "a": {
       "b": {
           "c": {
               "d": [
                   {
                       "e": {
                           "f": "value"
                       },
                       "e1": [
                           {
                               "f": "value"
                           }
                       ]
                   }]
           }
       }
   }
}

note: parentObj is non-mandatory, if key has same name is other object parentObj
var keys = "f";
var parentObj = "e1";
var res = complexJson.getPath(json, keys, parentObj);

Author

👤 vignesh

🤝 Contributing

Contributions, issues and feature requests are welcome!
Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!


complex-json developed with ❤️