# getJSON returns Cannot read json

**URL:** <https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971>\
**Category:** support\
**Created:** [March 10, 2018, 6:58am UTC](https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971 "2018-03-10T06:58:59Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![debos](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@debos](https://discourse.gohugo.io/u/debos)\
**Post date:** [March 10, 2018, 6:58am UTC](https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971/1 "2018-03-10T06:58:59Z")

</div>

Hi,

For a multilingual site, I would like to include a json data file as page resource.  
My content folder looks like this:

trekkings  
| tourbregaglia  
| | index.nl.md  
| | index.de.md  
| | index.en.md  
| | data.json

In my template, I try to read in the json file using:  
{{ $dataResource := (.Resources.GetMatch “data.json”).RelPermalink }}  
{{ $data := getJSON $dataResource }}

When generating, the following errors occur:  
Cannot read json from resource /de/trekkings/tourbregaglia/data.json with error message unexpected end of JSON input  
Cannot read json from resource /nl/trekkings/tourbregaglia/data.json with error message unexpected end of JSON input  
Cannot read json from resource /trekkings/tourbregaglia/data.json with error message unexpected end of JSON input

I tried it with different valid json files (valid according to [jsonlint.com](http://jsonlint.com)), even the most simple ones, the error always occurs.

Any help would be appreciated!

David

---

<div class="post-metadata">

**Author:** ![Mikhail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mikhail/32/1138_2.png) [@Mikhail](https://discourse.gohugo.io/u/Mikhail)\
**Post date:** [March 11, 2018, 10:11am UTC](https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971/2 "2018-03-11T10:11:37Z")

</div>

> [@debos](#):
>
> {{ $data := getJSON $dataResource }}

> [Load Local files](https://gohugo.io/templates/data-templates/#implementation-details)  
> To load local files with getJSON and getCSV, the source files must reside within Hugo’s working directory. The file extension does not matter, but the content does.

Did you check if the paths coincide .RelPermalink and “Hugo’s working directory”?

---

<div class="post-metadata">

**Author:** ![debos](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@debos](https://discourse.gohugo.io/u/debos)\
**Post date:** [March 11, 2018, 12:21pm UTC](https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971/3 "2018-03-11T12:21:40Z")

</div>

Hi Mikhail,

I don’t understand what you mean by that. Could you be more precise what I should check?

The RelPermalink in my case equals ‘trekkings/tourbregaglia/data.json’, Hugo’s working directory is the root directory of my site I guess?

David

---

<div class="post-metadata">

**Author:** ![Mikhail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mikhail/32/1138_2.png) [@Mikhail](https://discourse.gohugo.io/u/Mikhail)\
**Post date:** [March 11, 2018, 12:28pm UTC](https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971/4 "2018-03-11T12:28:51Z")

</div>

The RelPermalink `trekkings/tourbregaglia/data.json`

Files path `/content/trekkings/tourbregaglia/data.json`

It does not look the same.

---

<div class="post-metadata">

**Author:** ![debos](https://avatars.discourse-cdn.com/v4/letter/d/ee59a6/32.png) [@debos](https://discourse.gohugo.io/u/debos)\
**Post date:** [March 11, 2018, 6:57pm UTC](https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971/5 "2018-03-11T18:57:35Z")

</div>

Thanks for the hint.  
If I change my template now to  
{{ $dataResource := (.Resources.GetMatch “data.json”).RelPermalink }}  
{{ $data := getJSON “content” $dataResource }}  
it works for the default language (english), but not for the other two languages, because the RelPermalink includes ‘de’ or ‘nl’, and there is no /content/nl/ or /content/de/ directory…

So my question ‘getJSON returns Cannot read json’ is solved (thanks Mikhail!) but another question arises then: how to use Data Driven Content (as described here [https://gohugo.io/templates/data-templates/#data-driven-content](https://gohugo.io/templates/data-templates/#data-driven-content)) for a multilingual site? Will post a new post for that question 🙂

---

<div class="post-metadata">

**Author:** ![Mikhail](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/mikhail/32/1138_2.png) [@Mikhail](https://discourse.gohugo.io/u/Mikhail)\
**Post date:** [March 11, 2018, 7:58pm UTC](https://discourse.gohugo.io/t/getjson-returns-cannot-read-json/10971/6 "2018-03-11T19:58:54Z")

</div>

I did not make multilingual sites. I can advise looking at the [variables](https://gohugo.io/variables/page/) `.Lang` and `.Language`. And use the language prefix in the file name. /data/en.json etc.
