Fetching data from JSON file stored in S3


Is getJSON the right function to read from a JSON file stored in S3? Or should this be done with js.Build in this case?

Hello. I aim to display data from a JSON file I am storing (publicly) in S3 on my HUGO based website. This JSON file will be updated multiple times per day.

So far, I have not been able to resolve this with the getJSON.
And I am not sure whether this can work at all. Therefore I would appreciate any kind of suggestion on how to approach this.

This is a demo version of the JSON file:


{{ $data := "" }}
{{ $url := "https://pegel-konstanz-for-website.s3.eu-central-1.amazonaws.com/json/demo.json" }}
{{ with resources.GetRemote $url }}
  {{ with .Err }}
    {{ errorf "%s" . }}
  {{ else }}
    {{ $data = . | transform.Unmarshal }}
  {{ end }}
{{ else }}
  {{ errorf "Unable to get remote resource %q" $url }}
{{ end }}

<pre>{{ jsonify (dict "indent" "  ") $data }}</pre>

Works great.

It does.
Wow. Thank you for your help.

resources.GetRemote is exactly what I needed, from what I see.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.