Problem with "null" in a JSON

Hi all!

I’m using external JSON file to show some data on a site.

Typically there is a structure like:

"data": {
                "Choose_app_service_you_want_to_l": "Sherlock",
                "Feedback_type": [],
                "Usability": 4,
                "Usefulness": 4
            },

I’m using it with code:

{{ $choosen_tool := .data.Choose_app_service_you_want_to_l}}

But recently I saw in JSON items like this:

"data": null,

What ends with error:
nil pointer evaluating interface {}.Choose_app_service_you_want_to_l

I’ve tried “with”, I’ve tried if ne .data “null”, I’ve tried if eq .data “null” - nothing helps.

Is there a way to make Hugo ignore items with data: null?

Thanks!

Maybe because I should use “nil”…

{{ if ne .data nil }}

:slight_smile:

This post was like talking to small, yellow rubber duck :slight_smile:

But I would be surprised if this also did not work:

{{ if .data }}
{{ end }}

Are you sure about that?

Both

{{ if ne .data nil }}

and

{{ if .data }}

works

1 Like