I have an object which has a basic structure as below. So it is a dynamic array of n sections with dynamic number of fields within it.
let sections = [{
"id": "my-section-1",
"visible": true,
"fields": [{}]
}
]
Also, any of these section can have like a row of information/fields within it, in which case the structure is as below:
let sections = [{
"id": "my-section-1",
"visible": true,
"fields": [{
"gridItems": [{
}] // Array of fields
}]
}
]
Below is a more expanded/complete example with multiple attributes:
let sections = [
{
"id": "my-section-1",
"visible": true,
"fields": [{
"id": "my-field-1",
"mandatory": true,
"items": {},
"gridItems": [],
"value": "My Field Val 1",
"fieldLabel": "My Field",
},{
"id": "my-field-with-container-2",
"mandatory": true,
"items": {},
"gridItems": [{
"id": "my-grid-item-field-1",
"mandatory": true,
"items": {},
"value": "My Grid Item Field Val 1",
"fieldLabel": "My Field",
},{
"id": "my-grid-item-field-2",
"mandatory": true,
"items": {},
"value": "My Grid Item Field Val 2",
"fieldLabel": "My Field",
}
],
"value": "My Container Field",
"fieldLabel": "My Field",
}]
}, {
"id": "my-section-2",
"visible": true,
"fields": [
]
}
]
There are certain field attributes which I would have on the client-side and few on the server-side. I can have objects on both the sides (can use common field/section IDs to identify).
How can I merge the two?
So if my client-side object is as below:
let sections = [
{
"id": "my-section-1",
"visible": true,
"fields": [{
"id": "my-field-1",
"mandatory": true,
"items": {},
"gridItems": []
},{
"id": "my-field-with-container-2",
"mandatory": true,
"items": {},
"gridItems": [{
"id": "my-grid-item-field-1",
"mandatory": true,
"items": {}
},{
"id": "my-grid-item-field-2",
"mandatory": true,
"items": {}
}
]
}]
}, {
"id": "my-section-2",
"visible": true,
"fields": [
]
}
]
and the server-side object is as below:
let sections = [
{
"id": "my-section-1",
"visible": true,
"fields": [{
"id": "my-field-1",
"value": "My Field Val 1",
"fieldLabel": "My Field",
},{
"id": "my-field-with-container-2",
"gridItems": [{
"id": "my-grid-item-field-1",
"value": "My Grid Item Field Val 1",
"fieldLabel": "My Field",
},{
"id": "my-grid-item-field-2",
"value": "My Grid Item Field Val 2",
"fieldLabel": "My Field",
}
],
"value": "My Container Field",
"fieldLabel": "My Field",
}]
}, {
"id": "my-section-2",
"visible": true,
"fields": [
]
}
]
Is there some JavaScript library that I can use to merge these two? Also, in case it makes it easier, I can tweak the structure slightly.
Note there is only one level nesting for gridItems i.e. it can only contain array of fields, but the inner fields cannot have any further gridItems.