Reputation: 37
I have an existing params object as following
{
"application_context": {
"application_id": "a0",
"context_id": "c0"
},
"device_data": {
"device_id": "",
"hostname": ""
},
"query_options": {
"page_token": "",
"page_size": 30
}
}
My desired object should be following
{
"application_context": {
"application_id": "a0",
"context_id": "c0"
},
"device_data": {
"device_id": "",
"hostname": ""
},
"query_options": {
"page_token": "",
"page_size": 30,
"filter_list": [{
"operator": "OPERATOR_AND",
"field_list": [{
"field": "State",
"value": "INACTIVE_STATE"
}]
}]
}
}
I have created the following
param['filter_list'] = [{
'operator': 'OPERATOR_AND',
'field_list': filter
}];
where it's adding the following part with some logic
"field": "State",
"value": "INACTIVE_STATE"
But not able to add the above to get my complete object
Upvotes: 0
Views: 51
Reputation: 3629
You can add your data as: obj["query_options"]["filter_list"] = param["filter_list"];
var obj = {
"application_context": {
"application_id": "a0",
"context_id": "c0"
},
"device_data": {
"device_id": "",
"hostname": ""
},
"query_options": {
"page_token": "",
"page_size": 30
}
};
var filter = [{
"field": "State",
"value": "INACTIVE_STATE"
}];
/*param['filter_list'] = */
var filter_list = [{
"operator": "OPERATOR_AND",
"field_list": filter
}]
obj["query_options"]["filter_list"] = filter_list ;
console.log(obj);
Upvotes: 1
Reputation: 50291
You need to create filter_list
on query_options
key
let data = {
"application_context": {
"application_id": "a0",
"context_id": "c0"
},
"device_data": {
"device_id": "",
"hostname": ""
},
"query_options": {
"page_token": "",
"page_size": 30
}
}
data.query_options.filter_list = [{
"operator": "OPERATOR_AND",
"field_list": [{
"field": "State",
"value": "INACTIVE_STATE"
}]
}];
console.log(data)
Upvotes: 1