# JSON error in pulling in simple key:value pairs

**URL:** <https://discourse.gohugo.io/t/json-error-in-pulling-in-simple-key-value-pairs/12121>\
**Category:** support\
**Created:** [May 23, 2018, 10:03pm UTC](https://discourse.gohugo.io/t/json-error-in-pulling-in-simple-key-value-pairs/12121 "2018-05-23T22:03:27Z")\
**Posts on this page:** 5\
**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:** [May 23, 2018, 10:03pm UTC](https://discourse.gohugo.io/t/json-error-in-pulling-in-simple-key-value-pairs/12121/1 "2018-05-23T22:03:28Z")

</div>

I’m trying to replace some static values in content files with data from a curated JSON document, via shortcodes.

Data file: design-tokens/tokens.json

```auto
{
  "COLOR_TEXT_LINK": "#098ae4",
  "COLOR_TEXT_LINK_VISITED": "#098ae4",
  "COLOR_TEXT_LINK_HOVER": "#004d81",
  "COLOR_TEXT_LINK_ACTIVE": "#098ae4",
  "COLOR_TEXT_LINK_DISABLED": "#333333"
}

```

Content file: buttons.md

```auto
{{% datapoint token="COLOR_TEXT_LINK" %}}

```

Shortcode file: datapoint.html

```auto
{{ $token := .Get "token" }}
{{ $data := getJSON "./design-tokens/tokens.json" }}
{{ range $data }}
{{ $token }}
{{ end }}

```

Produces this error:

```auto
Building sites … ERROR 2018/05/23 16:57:11 Cannot read json from resource ./design-tokens/tokens.json with error message unexpected end of JSON input

```

The idea here is that I’m maintaining my list of tokens in one file and they will always get replaced in the content with updated hex codes. The above may be overkill, or just incorrect syntax all around. After researching and trying many things, I’m resorting to asking here!

---

<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:** [May 23, 2018, 10:40pm UTC](https://discourse.gohugo.io/t/json-error-in-pulling-in-simple-key-value-pairs/12121/2 "2018-05-23T22:40:08Z")

</div>

I would suggest you try the JSON in an online JSON validator.

That said, I would recommend you put these types of JSON files into /data,

If /data/design\_tokens/tokens.json

You can access it with .Site.Data.design\_tokens.tokens (note me not using a hyphen, which would have made the lookup more complex).

Also, I don’t understand your “range syntax”, but that is a problem for the future, I guess.

---

<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:** [May 25, 2018, 7:03pm UTC](https://discourse.gohugo.io/t/json-error-in-pulling-in-simple-key-value-pairs/12121/3 "2018-05-25T19:03:09Z")

</div>

Yep, that definitely makes things simpler, so I ended up using this bit in my shortcode template:

```auto
{{ $token := .Get "token" }}
{{ $data := .Site.Data.design_tokens.tokens }}
{{ index $data $token }}

```

Thanks!

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [February 19, 2020, 10:41am UTC](https://discourse.gohugo.io/t/json-error-in-pulling-in-simple-key-value-pairs/12121/4 "2020-02-19T10:41:07Z")

</div>

A post was split to a new topic: [Help with getJSON: unexpected end of JSON input](https://discourse.gohugo.io/t/help-with-getjson-unexpected-end-of-json-input/23532)

---

<div class="post-metadata">

**Author:** ![pointyfar](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/pointyfar/32/5797_2.png) [@pointyfar](https://discourse.gohugo.io/u/pointyfar)\
**Post date:** [February 19, 2020, 10:44am UTC](https://discourse.gohugo.io/t/json-error-in-pulling-in-simple-key-value-pairs/12121/5 "2020-02-19T10:44:43Z")

</div>


