Inconsistencies in supported data formats

In the various ways to use data files in Hugo, there are inconsistencies:

  • data folder: Supports JSON, TOML and YAML
  • getJSON, getCSV : Adds CSV format but does not support YAML/TOML
  • transform.Unmarshal: Supports JSON, YAML, TOML and CSV.

There should be consistency in supported file formats.

Update: Since the the issue is closed already:
I was hoping to get consistency. data folder cannot hold a CSV file. There is no getYAML to load a YAML file from disk. It seems that is not desired. That’s ok. Just wanted confirmation.

Is there a problem you’re trying to solve?

Why would a function called getJSON support other formats than JSON?

Likewise why would getCSV support anything other than CSV?

I am closing this topic. This is not really a Support Ticket.

But you can use Data templates to render attributes from YAML in the Data folder and a CSV can reside under the assetsDir

Also note that file types in the data folder have been decided a long time ago.

I re-opened the topic since you provided clarification about what you’re trying to do.

There is certainly a history here. There is at least one issue about adding remote support in resources.Get which would make getJSON/getCsv superflous, as you could do:

{{ $data := resources.Get "https://example.org/foo.json" | transform.Unmarshal }}

I’m not sure how CSV files maps into the /data map, but if you have a proposal, please shout.

1 Like

Agreed about resources.Get having http support will get rid of the getJSON like methods.

For the data folder, just like transform.Unmarshal creates an array of arrays in the return value, if there is a CSV file within the data folder, that could convert to the same format within the $.Site.Data object (we can assume commas as separators by default since CSV stands for Comma Separated Values).

More than a feature request, I am looking for clarity on the approach and direction regarding these features. In some sense, the $.Site.Data variable is redundant as we could create a cached partial to read the values and return them. Since the Hugo documentation carries the Data templates section, I am interested in understanding its best use cases.