JSFiddle - React, Tailwind, and code Playground
JavaScript
var obj = {
"data": {
"VersionForTarget": "1",
"RulesContainer": {
"Rule": { // <--- New Rule Goes Here
"RuleParentID": "1",
"RuleVersionID": "1",
"MappedValue": "1",
"ProcessingOrder": "1",
"MetaInsertUtc": "2017-03-03T17:54:34.643",
"Value": "Omaha",
"IsRuleRetired": "0",
"UserImpactCount": "2277",
"AttributeContainer": {
"Attribute": { // <--- New Attribute Goes Here
"AttributeID": "6",
"AttributeName": "Campus",
"AttributeDetailsContainer": {
"AttributeDetails": { // <--- New Attribute Details Goes Here
"RuleDetailID": "1",
"AttributeID": "6",
"OperatorID": "3",
"AttributeValue": "1",
"RuleParentID": "1",
"Value": "Omaha",
"IsValueRetired": "0",
"OperatorName": "In List",
"SqlOperator": "IN"
}
}
}
}
}
}
}
};
// This will add a new rule to the object
function addRule() {
var newRule = {
"RuleParentID": "3",
"RuleVersionID": "1",
"MappedValue": "4",
"ProcessingOrder": "5",
"MetaInsertUtc": "2017-03-03T17:54:34.643",
"Value": "New Thing",
"IsRuleRetired": "0",
"UserImpactCount": "2277"
};
}
// This will add a new attribute to the object
function addAttribute(RuleParentID) {
// Add attribute object in our parent rule
var newAttribute = {
"AttributeID": "6",
"AttributeName": "Campus",
}
}
// This will add new attribute details to the object
function addAttributeDetails(RuleParentID, AttributeID) {
// Add attribute details to our specified attribute in our specified parent rule
var newAttributeDetails = {
"RuleDetailID": "1",
"AttributeID": "6",
"OperatorID": "3",
"AttributeValue": "1",
"RuleParentID": "1",
"Value": "Omaha",
...