# Accessing JSON data files with extra dots in file names

**URL:** <https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498>\
**Category:** support\
**Created:** [November 26, 2018, 3:22pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498 "2018-11-26T15:22:10Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![bradbice](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bradbice/32/14162_2.png) [@bradbice](https://discourse.gohugo.io/u/bradbice)\
**Post date:** [November 26, 2018, 3:22pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/1 "2018-11-26T15:22:10Z")

</div>

I have a list of data files I’m copying into my /data (specifically /data/data\_files) folder that have an extra dot in their file names, like so:

```auto
prices.full.json

```

I was previously able to use the following to pass the `item` name in and find the corresponding data file in my data folder.

```auto
{{ $name := .Get "name" }}
{{ $data := index .Site.Data.data_files $name }}

```

Which would find something like `prices.json` if I passed in the name `prices`.

However, now that my set of files has `.full` added to it, it’s breaking my call. So for example, the data file is now called `prices.full.json`.

Is there a specific way I should alter my `index` call to access these now?

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [November 26, 2018, 4:09pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/2 "2018-11-26T16:09:35Z")

</div>

I have run into the same thing, even when not using `index`.

For example, given a data file named `file.json`, and a copy of that file named `file.foo.json`:

This works:

```auto
{{ range := .Site.Data.file }}

```

But this doesn’t:

```auto
{{ range := .Site.Data.file.foo }}

```

* * *

_Edit:_ from the [data templates docs](https://gohugo.io/templates/data-templates/), this is why things are the way they are:

> The keys in the map created with data templates from data files will be a dot-chained set of `path`, `filename`, and `key` in file (if applicable).

@bradbice so I think picking another naming convention is the way to go. Such as

```auto
prices_full.json

```

Or

```auto
pricesFull.json

```

---

<div class="post-metadata">

**Author:** ![bradbice](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bradbice/32/14162_2.png) [@bradbice](https://discourse.gohugo.io/u/bradbice)\
**Post date:** [November 26, 2018, 5:15pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/3 "2018-11-26T17:15:11Z")

</div>

Yeah, I’m hoping that’s not the only option because these files are coming from elsewhere and I don’t have control over their names.

Really hoping I don’t have to rewrite the file names with Gulp or something each time I import them.

**Update:**

So far I am rewriting the file names with Gulp using the following:

```auto
gulp.task('copy-tokens', ['clean'], function() {
    gulp.src(['source/*.json'])
        .pipe(
            rename(function(path) {
                path.basename = path.basename.replace('.full', '');
                return path;
            })
        )
        .pipe(gulp.dest('data/data_files/'));

```

It works fine, but as an extra step it’s making me ☹

---

<div class="post-metadata">

**Author:** ![ju52](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/ju52/32/6749_2.png) [@ju52](https://discourse.gohugo.io/u/ju52)\
**Post date:** [November 26, 2018, 6:46pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/4 "2018-11-26T18:46:35Z")

</div>

This works for me

```
{{ $file := .Params.datafile}}{{ $data := getJSON $file }}
{{ range sort $data.items "title"}}

{{end}}

```

with

```
+++
<snipped>
datafile = "/assets/links/my.links.copy.json"
+++

```

If you use /assets, the file will not copied to your web site

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [November 26, 2018, 6:56pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/5 "2018-11-26T18:56:43Z")

</div>

> [@bradbice](#):
>
> I was previously able to use the following to pass the `item` name in and find the corresponding data file in my data folder.

Assuming you pass “prices.full” in your name parameter, I cannot see how your code should not work …? It could be a bug, but I doubt it.

---

<div class="post-metadata">

**Author:** ![bradbice](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bradbice/32/14162_2.png) [@bradbice](https://discourse.gohugo.io/u/bradbice)\
**Post date:** [November 26, 2018, 7:00pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/6 "2018-11-26T19:00:32Z")

</div>

@bep That’s true, I could try that.

I was attempting this way because I was hoping to edit just one shortcode file rather than dozens of individual content pages with shortcode calls, all with just the same `.full` added…

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [November 26, 2018, 7:13pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/7 "2018-11-26T19:13:47Z")

</div>

Looking at this again, I was mistaken. Sorry about that.

Using `index` for a data file with an extra dot in the name does indeed work. Here’s my test case:

A data file at `data/file.foo.json` with these contents:

```auto
{
  "product_1": "10.00",
  "product_2": "20.00",
  "product_3": "30.00"
}

```

Then in the template:

```auto
{{ $name := "file.foo" }}
{{ $data := index .Site.Data $name }}
{{ range $key, $value := $data }}
  {{ $key }} = {{ $value }}<br>
{{ end }}

```

* * *

@bradbice for your shortcode `name` param, are you passing `"prices.full.json"` or `"prices.full"` ?

---

<div class="post-metadata">

**Author:** ![bradbice](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bradbice/32/14162_2.png) [@bradbice](https://discourse.gohugo.io/u/bradbice)\
**Post date:** [November 26, 2018, 8:26pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/8 "2018-11-26T20:26:57Z")

</div>

I’m only passing in `"prices"`, in case the data format changes someday, and since I should only have to pass through the content, not the file format. And it worked just fine using `index`, but now it’s looking for `prices.json` and only finding `prices.full.json` and returning null.

I could change what I’m passing, but I’m doing this on multiple pages and wanted to only update the shortcode, as I mentioned above.

---

<div class="post-metadata">

**Author:** ![zwbetz](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/zwbetz/32/16088_2.png) [@zwbetz](https://discourse.gohugo.io/u/zwbetz)\
**Post date:** [November 26, 2018, 8:30pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/9 "2018-11-26T20:30:25Z")

</div>

If I’m understanding you correctly, since your data filename has changed, you now need to pass `"prices.full"` instead of `"prices"`

---

<div class="post-metadata">

**Author:** ![bradbice](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bradbice/32/14162_2.png) [@bradbice](https://discourse.gohugo.io/u/bradbice)\
**Post date:** [November 26, 2018, 8:34pm UTC](https://discourse.gohugo.io/t/accessing-json-data-files-with-extra-dots-in-file-names/15498/10 "2018-11-26T20:34:37Z")

</div>

Yes 🙂

For now I’m instead just changing file names via Gulp.
