Make JSON based on available fields I am trying to create a filter string according to the fields available with the following code, how could i improve the following with a switch case or better way? 

   if ((this.selectedCity === 'City') &amp;&amp; this.selectedCategory === 'Category' &amp;&amp; this.fromDate === '') {
            this.filter = `{}`;
        } else if ((this.selectedCity !== 'City') &amp;&amp; this.selectedCategory === 'Category' &amp;&amp; this.fromDate === '') {
            this.filter = `{"location.city":"${this.selectedCity}"}`;
        } else if ((this.selectedCity === 'City') &amp;&amp; this.selectedCategory !== 'Category' &amp;&amp; this.fromDate === '') {
            this.filter = `{"category":"${this.selectedCategory}"}`;
        } else if ((this.selectedCity === 'City') &amp;&amp; this.selectedCategory !== 'Category' &amp;&amp; this.fromDate !== '') {
            this.filter = `{"date.start":{"$gte":"${this.fromDate}"},"date.end":{"$lt":"${this.toDate}"}}`;
        } else if ((this.selectedCity !== 'City') &amp;&amp; this.selectedCategory !== 'Category' &amp;&amp; this.fromDate === '') {
            this.filter = `{"location.city":"${this.selectedCity}","category":"${this.selectedCategory}"}`;
        } else if ((this.selectedCity !== 'City') &amp;&amp; this.selectedCategory === 'Category' &amp;&amp; this.fromDate !== '') {
            this.filter = `{"location.city":"${this.selectedCity}","date.start":{"$gte":"${this.fromDate}"},"date.end":{"$lt":"${this.toDate}"}}`;
        } else if ((this.selectedCity === 'City') &amp;&amp; this.selectedCategory === 'Category' &amp;&amp; this.fromDate !== '') {
            this.filter = `{"date.start":{"$gte":"${this.fromDate}"},"date.end":{"$lt":"${this.toDate}"}}`;
        } else if ((this.selectedCity !== 'City') &amp;&amp; this.selectedCategory !== 'Category' &amp;&amp; this.fromDate !== '') {
            this.filter = `{"location.city":"${this.selectedCity}","category":"${this.selectedCategory}","date.start":{"$gte":"${this.fromDate}"},"date.end":{"$lt":"${this.toDate}"}}`;
        }
I recommend building the filter in steps, starting with an empty object {}. You then add attributes according to the selected city, category and date. And finally, you convert it to a JSON string via JSON.stringify(filter): 

let filter = {};

if (this.selectedCity !== 'City') {
  filter.location = {
    city: this.selectedCity
  };
}

if (this.selectedCategory !== 'Category') {
  filter.category = this.selectedCategory;
}

if (this.fromDate !== '') {
  filter.date = {
    start: {'$gte': this.fromDate},
    end:   {'$lt':  this.toDate}
  };
}

this.filter = JSON.stringify(filter);