0

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

1
  • have you tried nameOfYourObject["query_options"].filter_list = param["filter_list"] ? Commented Oct 24, 2019 at 6:07

2 Answers 2

1

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)

Sign up to request clarification or add additional context in comments.

Comments

1

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);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.