Help needed with REST when empty/null value return

Hi,
I have a sensor configure to pull JSON from another server. sensor works fine when there is value returned but gives an error when there is a null value. how can avoid the error when there is empty JSON value.

Maybe try it with:

    value_template: >
      {% if value_json is defined %}
        {{ value_json['objects'][0].level }}
      {% else %}
        {{ states('sensor.fn_alert_level') }}
      {% endif %}

Not tested!

The concept worked, but I had to use “None” to indicate an empty return. Thanks

value_template: >
  {% if value_json is defined %}
    {{ value_json['objects'][0].level }}
  {% else %}
    {{ "None" }}
  {% endif %}

I ran into this too - This should really be in the restful sensor documentation. I ran into it too. It’s especially confusing because the error message is:

“Error fetching data: failed with Server disconnected without sending a response.”

Which isn’t correct; the server returned a 200 response, so saying “no response” is quite false.

I opened a ticket against HA core, we’ll see if its addressed:

One thing to note is how a JSON parser handles an empty string. In my elixir console, I did some testing and it appears that the string null (without quotes) is valid json, where a zero character string is not (which is what is currently being returned by my endpoints, at least)