title: Check if all fields in a json are set and non null
body: <p>I have a json like this</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;serial&quot;: &quot;34AS9831&quot;,
    &quot;sensor_type&quot;: &quot;Foo&quot;,
  
    &quot;value_registered&quot;: {
        &quot;value_type&quot;: &quot;temperature&quot;,
        &quot;value&quot;: 34.6,
        &quot;unit_of_measure&quot;: &quot;celsius&quot;
    },
  
    &quot;value_registered_at&quot;: &quot;24/08/2021 14:05:34&quot;
  }
  
  </code></pre>
  <p>I need to check if all fields are set, and they must be non null.</p>
  <p>The first solution is the follow:</p>
  <pre class="lang-js prettyprint-override"><code>try {
      check_request(req, res);
  
      let data = JSON.parse(req.body);
  
      let isJSONBadFormatted =
        data.serial                           == undefined ||
        data.serial                           == null ||
        data.sensor_type                      == undefined ||
        data.sensor_type                      == null ||
        data.value_registered                 == undefined ||
        data.value_registered                 == null ||
        data.value_registered.value_type      == undefined ||
        data.value_registered.value_type      == null ||
        data.value_registered.value           == undefined ||
        data.value_registered.value           == null ||
        data.value_registered.unit_of_measure == undefined ||
        data.value_registered.unit_of_measure == null ||
        data.value_registered_at              == undefined ||
        data.value_registered_at              == null;
  
      if(isJSONBadFormatted) {
        unprocessable_json(res);
        alert();
        return;
      }
  
      insertDataIntoDB(data);
  
    }catch(err){
      /* TODO: implement alert function */
      alert();
    }
  </code></pre>
  <p>But I don't like this way. Is there a solution to write it in a more elegant way?</p>