1.0.7 • Published 11 months ago
@dobuki/obj-assembler v1.0.7
obj-assembler
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.