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
georg
216k57 gold badges325 silver badges401 bronze badges
-
have you tried nameOfYourObject["query_options"].filter_list = param["filter_list"] ?Angen– Angen2019年10月24日 06:07:14 +00:00Commented Oct 24, 2019 at 6:07
2 Answers 2
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)
answered Oct 24, 2019 at 6:09
brk
50.3k10 gold badges59 silver badges85 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
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);
answered Oct 24, 2019 at 6:10
Bilal Siddiqui
3,6491 gold badge16 silver badges22 bronze badges
Comments
lang-js