you can use AJV to define a schema where the fields property changes based on the type using if then else. eg. if type is GPS, the fields must have lat and lng, and no extra fields are allowed. Similarly for ROOM it should only have temp and humidity