# getJSON: Unexpected end of JSON input

**URL:** https://discourse.gohugo.io/t/getjson-unexpected-end-of-json-input/31197
**Category:** support
**Created:** [February 12, 2021, 8:19pm UTC](https://discourse.gohugo.io/t/getjson-unexpected-end-of-json-input/31197 "2021-02-12T20:19:08Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![mrverdantgreen](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mrverdantgreen](https://discourse.gohugo.io/u/mrverdantgreen)
#### Post date: [February 12, 2021, 8:19pm UTC](https://discourse.gohugo.io/t/getjson-unexpected-end-of-json-input/31197/1 "2021-02-12T20:19:08Z")

</div>

I cannot get accessing JSON either under the data directory or loading local JSON with the getJSON function to work.

Here is the attempt to access JSON from a data template:

```auto
    `{{/* JSON */}}
    {{ $json := index $.Site.Data.jaysawn "firstkey" }}
    <h2>{{ $json }}</h2>

```

And here is the YAML version:

```auto
    {{/* YAML */}}
    {{ $yaml := index $.Site.Data.yammel "firstkey" }}
    <h2>{{ $yaml }}</h2>`

```

Here is the JSON file data/yammel.json:

```auto
    {
    "firstkey": "firstvalue"
    }

```

And here is the YAML file data/yammel.yaml:  
`"firstkey": "firstvalue"`

When trying to access JSON from a data template, the index call fails with:  
`"error calling index: index of untyped nil"`  
Note that accessing the YAML works just fine.

When trying to access the JSON as a local file via getJSON, I get:  
`unexpected end of JSON input`  
I’ve tried putting the json file at the top level of the site directory, under the data dir, and other places, but always the same error.

Am I doing something wrong? Or is JSON just not working? I have a lot of data I need to access one way or another in templates, and the data is natively JSON. I could convert it to YAML with yq or similar, but it would add another step to an already lengthy process, so I’d rather not if I can get Hugo to read the JSON. Any thoughts or suggestions greatly appreciated!

---

<div class="post-metadata">

### Author: ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)
#### Post date: [February 12, 2021, 8:30pm UTC](https://discourse.gohugo.io/t/getjson-unexpected-end-of-json-input/31197/2 "2021-02-12T20:30:42Z")

</div>

From the errors you posted the JSON does not seem valid.

Have you tried validating it? See: [https://jsonlint.com/](https://jsonlint.com/)

Also JSON support is fine in Hugo v0.80.0 as well as in many previous versions, as far back as I can remember.

Furthermore see the forum [Requesting Help](https://discourse.gohugo.io/t/requesting-help/9132) guidelines.

---

<div class="post-metadata">

### Author: ![mrverdantgreen](https://avatars.discourse-cdn.com/v4/letter/m/a4c791/32.png) [@mrverdantgreen](https://discourse.gohugo.io/u/mrverdantgreen)
#### Post date: [February 12, 2021, 10:39pm UTC](https://discourse.gohugo.io/t/getjson-unexpected-end-of-json-input/31197/3 "2021-02-12T22:39:46Z")

</div>

So for posterity, this was the problem: I had `.json$` in the `ignoreFiles` array in the config file. I had thought that `ignoreFiles` was for keeping certain types of files out of the final build, but apparently it also disables JSON files in the data directory? Is this the intended behavior? If so, is there some other way of making sure that JSON files don’t make it into the final build?

In any case, removing JSON from `ignoreFiles` solves the problem or not being able to read JSON in data templates.

---

<div class="post-metadata">

### Author: ![alexandros](https://avatars.discourse-cdn.com/v4/letter/a/ecc23a/32.png) [@alexandros](https://discourse.gohugo.io/u/alexandros)
#### Post date: [February 13, 2021, 7:08am UTC](https://discourse.gohugo.io/t/getjson-unexpected-end-of-json-input/31197/4 "2021-02-13T07:08:57Z")

</div>

> [@mrverdantgreen](#):
>
> If so, is there some other way of making sure that JSON files don’t make it into the final build?

In the `ignoreFiles` array, you can specify the folder in which you want to disable JSON or other file formats, e.g. `"/content/\\.json$"`

---

<div class="post-metadata">

### Author: ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)
#### Post date: [February 15, 2021, 7:09am UTC](https://discourse.gohugo.io/t/getjson-unexpected-end-of-json-input/31197/5 "2021-02-15T07:09:22Z")

</div>

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