# Unable to sort or fully read data json

**URL:** <https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141>\
**Category:** support\
**Created:** [October 31, 2020, 2:23am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141 "2020-10-31T02:23:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![whippersnapper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/whippersnapper/32/12643_2.png) [@whippersnapper](https://discourse.gohugo.io/u/whippersnapper)\
**Post date:** [October 31, 2020, 2:23am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/1 "2020-10-31T02:23:31Z")

</div>

For one of my list pages, I’m trying to read data from `data/foo.json`. The json looks like this.

```auto
{
  "metadata": {
    "title": "Lorem ipsum dolor sit amet, consectetur adipisicing elit",
    "full": "Lorem ipsum dolor sit amet, consectetur adipisicing elit",
    "date": "2020-06-15",
    "link": "https://arxiv.org/abs/111"
  },
  "rocker": {
    "title": "Lorem ipsum dolor sit amet, consectetur adipisicing elit",
    "full": "Lorem ipsum dolor sit amet, consectetur adipisicing elit",
    "date": "2020-08-17",
    "link": "https://arxiv.org/abs/1111"
  }
} 

```

On my list.html, I am trying to read these json entries and sort them.

```auto
{{ $json := getJSON "data/foo.json" }}
{{ range sort $json "date" "desc" }}
<!-- TODO: This only returns 5 results. Why??? -->
    <div class="post">
      <h2><a href="#">{{ .title }}</a></h2>
      <p>{{ .full }}</p>
      <div class="multi-links">
        <a href="{{ .link }}" class="link icon-link icon-publication">View Publication</a>
      </div>
    </div>
{{end}}

```

There are two problems. It doesn’t seem to understand or sort by date.  
It also only returns 5 results when the json contains dozens more.

Can someone point me to what I’m doing wrong?

Thanks very much for any leads.

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [October 31, 2020, 3:03am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/2 "2020-10-31T03:03:18Z")

</div>

Does using `$.Site.Data` instead of `getJSON` change anything? See [https://gohugo.io/templates/data-templates/](https://gohugo.io/templates/data-templates/).

---

<div class="post-metadata">

**Author:** ![whippersnapper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/whippersnapper/32/12643_2.png) [@whippersnapper](https://discourse.gohugo.io/u/whippersnapper)\
**Post date:** [October 31, 2020, 3:07am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/3 "2020-10-31T03:07:37Z")

</div>

Similar outcome, unfortunately

---

<div class="post-metadata">

**Author:** ![moorereason](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/moorereason/32/592_2.png) [@moorereason](https://discourse.gohugo.io/u/moorereason)\
**Post date:** [October 31, 2020, 3:36am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/4 "2020-10-31T03:36:42Z")

</div>

I’m not able to reproduce this. What does `hugo version` show?

---

<div class="post-metadata">

**Author:** ![whippersnapper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/whippersnapper/32/12643_2.png) [@whippersnapper](https://discourse.gohugo.io/u/whippersnapper)\
**Post date:** [October 31, 2020, 4:33am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/5 "2020-10-31T04:33:17Z")

</div>

Hugo version is `v0.74.3`.

Perhaps I’m unclear on the `$.Site.Data` syntax (Still getting used to Hugo syntax).

Would I use

```auto
{{ range .Site.Data.foo }}

```

where the data reside in `data/foo.json`?  
This works, but I am still not able to sort by `date` or show all entries (it’s still limited to 5).

---

<div class="post-metadata">

**Author:** ![whippersnapper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/whippersnapper/32/12643_2.png) [@whippersnapper](https://discourse.gohugo.io/u/whippersnapper)\
**Post date:** [October 31, 2020, 5:50am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/6 "2020-10-31T05:50:35Z")

</div>

Big apologies @moorereason

The error was on my part. I was still testing the json approach so the dates were wrong. Once I fixed those, my original approach worked just fine. Thanks very much for your help!

facepalm

---

<div class="post-metadata">

**Author:** ![whippersnapper](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/whippersnapper/32/12643_2.png) [@whippersnapper](https://discourse.gohugo.io/u/whippersnapper)\
**Post date:** [October 31, 2020, 5:52am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/7 "2020-10-31T05:52:35Z")

</div>

The problem with the 5 results only was that a bunch of json entries had the same key and it just picked the last one. This is also fixed.

---

<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:** [November 2, 2020, 5:52am UTC](https://discourse.gohugo.io/t/unable-to-sort-or-fully-read-data-json/29141/8 "2020-11-02T05:52:37Z")

</div>

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