@dobuki/obj-assembler

1.0.7 • Public • Published

obj-assembler


CodeQL

pages-build-deployment

npm version


Basic usage:

ObjAssembler is meant mainly to build complex JSON objects out of multiple JSON files. Commonly, you have one master JSON files that will be composed of multiple objects. Rather than have one large file, you can take pieces of them and put them into separate file.

For instance, to achieve the following:

graph TD;
    jsonA-->master;
    jsonB-->master;
    jsonC-->master;

Have your master file as follow:

master:

{
  "componentA": {
    "type": "json",
    "src": "jsonA.json"
  },
  "componentB": {
    "type": "json",
    "src": "jsonB.json"
  },
  "componentC": {
    "type": "json",
    "src": "jsonC.json"
  }
}

Then fill each child jsons with content.

jsonA:

{
   "fieldA": 123
}

jsonB:

{
   "fieldB": "this is content B"
}

jsonC:

["a", "b", "c"]

Compose the JSON using the code below:

import Assembler from "obj-assembler"

const masterJSON = loadJsonFile("master.json"); //  masterJSON should be an object.

const assembler = new Assembler();
assembler.assemble(masterJSON);

This will result in the following JSON:

{
  "componentA": {
      "fieldA": 123
  },
  "componentB": {
   "fieldB": "this is content B"
  },
  "componentC": ["a", "b", "c"]
}

See below for more advance usage.

Advanced usage readme:

link to usage

Demo

demo

Readme

Keywords

none

Package Sidebar

Install

npm i @dobuki/obj-assembler

Weekly Downloads

0

Version

1.0.7

License

ISC

Unpacked Size

589 kB

Total Files

53

Last publish

Collaborators

  • vincentlequang