How to check when I get response that it is in JSON format and to add validation

When I get the response I would like to check whether is in JSON presented and to add validation for true or false in the test.

Hello @satellite-geoscient2 :wave:
Welcome to the community :blush:

I think you can check it that way :point_down:

const jsonData = pm.response.json();

pm.test("Check if response is json", function() {    
    pm.expect(jsonData).to.be.an('object');
});

Hello, I tried doing this, but I got an error when the response was empty: There was an error in evaluating the test script: JSONError: No data, empty input at 1:1 ^

How can I factor that into my tests?