# JSON link array does not match link order in post

**URL:** <https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205>\
**Category:** Support\
**Created:** [February 10, 2017, 1:14pm UTC](https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205 "2017-02-10T13:14:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![samnazarko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samnazarko/32/109010_2.png) [@samnazarko](https://meta.discourse.org/u/samnazarko)\
**Post date:** [February 10, 2017, 1:14pm UTC](https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205/1 "2017-02-10T13:14:11Z")

</div>

Hello

We are using [Discourse to power our Wiki](https://blog.discourse.org/2016/05/using-discourse-as-a-community-powered-wiki/). It’s been working pretty well. Since updating to 1.7 we’ve run in to a slight snag. It seems that the ordering of the links to other Wiki pages is not necessarily respected.

If you see our Table of Contents for the Wiki [here](https://discourse.osmc.tv/t/table-of-contents/6543), you will see that Apple TV is the second to last link, and we would like it to be the second to last category to appear. Our script scrapes the links array. I have noticed that the JSON of the post [lists Apple TV first](https://discourse.osmc.tv/t/table-of-contents/6543). At first I thought Discourse may be ordering links by post ID, but this does not seem to be the case. I tried editing the post and removing all links, and then re-adding them, but this did not change the situation.

Is there an explanation for how the links array is ordered? Would it make sense for the links to be listed in the JSON in the order that they are referenced?

```
  "links":[  
     {  
        "url":"https://discourse.osmc.tv/t/apple-tv/10039",
        "title":"Apple TV",
        "fancy_title":null,
        "internal":true,
        "attachment":false,
        "reflection":false,
        "clicks":0,
        "user_id":1,
        "domain":"discourse.osmc.tv"
     },

```

]

Thanks

Sam

---

<div class="post-metadata">

**Author:** ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)\
**Post date:** [February 10, 2017, 3:35pm UTC](https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205/2 "2017-02-10T15:35:52Z")

</div>

I believe those links are ordered in terms of popularity. The most clicked on links will be at the top.

---

<div class="post-metadata">

**Author:** ![vinothkannans](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/vinothkannans/32/86465_2.png) [@vinothkannans](https://meta.discourse.org/u/vinothkannans)\
**Post date:** [February 10, 2017, 3:37pm UTC](https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205/3 "2017-02-10T15:37:53Z")

</div>

> <https://github.com/discourse/discourse/blob/main/app/models/topic_link.rb#L54>

> [@eviltrout](#):
>
> I believe those links are ordered in terms of popularity. The most clicked on links will be at the top.

Yes.

---

<div class="post-metadata">

**Author:** ![samnazarko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samnazarko/32/109010_2.png) [@samnazarko](https://meta.discourse.org/u/samnazarko)\
**Post date:** [February 10, 2017, 9:27pm UTC](https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205/4 "2017-02-10T21:27:59Z")

</div>

Thanks for the information. I’ll have to find an appropriate workaround.

Sam

---

<div class="post-metadata">

**Author:** ![samnazarko](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/samnazarko/32/109010_2.png) [@samnazarko](https://meta.discourse.org/u/samnazarko)\
**Post date:** [February 12, 2017, 3:36am UTC](https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205/5 "2017-02-12T03:36:47Z")

</div>

You have `link_counts`, so you could add correct ordering there, but preserve links as is in a future version of Discourse, or maybe add a ‘links\_raw’. If you would accept a new JSON property that offers links in the correct order then I can PR this.

I will have to work around this temporarily by taking cooked and taking links from that or patching Discourse.

Sam

---

<div class="post-metadata">

**Author:** ![JammyDodger](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/jammydodger/32/254611_2.png) [@JammyDodger](https://meta.discourse.org/u/JammyDodger)\
**Post date:** [August 19, 2022, 5:05pm UTC](https://meta.discourse.org/t/json-link-array-does-not-match-link-order-in-post/57205/8 "2022-08-19T17:05:44Z")

</div>


