Range through a json file who's name is dynamically available

Let’s first say I have an JSON file named users.json and I wish to iterate through the data in it to display the full name of every user. I would do it like this:

{{ range .Site.Data.users}}
        <li>{{.first}} {{.last}}</li>
{{ end }}

If instead I have multiple json files for multiple pages and for each page I have an .md (markdown) file that stores (among other things) the name of its json file to use in a variable called datafile I would do:

{{ range .Site.Data.{{.Params.datafile}}}}
        <li>{{.first}} {{.last}}</li>
{{ end }}

This does not work.

What shall i do instead?

Try:

{{ range (index .Site.Data .Params.datafile) }}

If I have:

{{ $dataFile := index .Site.Data.business "paying-users"}}

{{range $dataFile.data.filters}}
        <li>{{.first}} {{.last}}</li>
{{ end }}

How do I get paying-users out of the .md file instead of hardcodeing it?

Try

.Params.paying-users

I need to use a variable, not the explicit filename. The datafile variable is what I need to be able to use.

Assuming your front matter contains that param:

{{ $dataFile := index .Site.Data.business .Params.datafile }}