# How to sort a JSON for a Flex Repeater

**URL:** <https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093>\
**Category:** Ignition\
**Created:** [October 19, 2021, 5:32am UTC](https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093 "2021-10-19T05:32:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![user39](https://avatars.discourse-cdn.com/v4/letter/u/59ef9b/32.png) [@user39](https://forum.inductiveautomation.com/u/user39)\
**Post date:** [October 19, 2021, 5:32am UTC](https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093/1 "2021-10-19T05:32:30Z")

</div>

Ok, so ill try to keep this brief.

I have a flex repeater that accepts a SQL Query as a Json file. This is my Database query:

select station\_number as “StationNum”, “” as “StationState” from stations

I added the “StationState” because I want to sort my Json, so that the repeater puts some of them at the bottom of the list, depending on the value of “StationState”, and the only way I know how to dynamically sort the Flex Repeater is with a Dynamic Json file.

So what ive decided to try to do is use a For repeater to add the values of the Tags to each row of the table, and then sort it. Ive been working on it for a while and just cant come up with the right answer. This is what Ive come up with so far:

pyData = system.dataset.toPyDataSet(value)

```
for row in range(value.getRowCount()):
	count = row +1
	Tag = system.tag.readBlocking("[default]GoldSim/Station "+ str(count) +"/State tag")
	NewData = system.dataset.setValue(value, row, "StationState", Tag)
	
return NewData

```

Is there a easier way to do this? It feels like I’m missing something simple here. Now I think I have to convert the Dataset back to a Json, but im not sure how to do that.

Im quite new to Python and working with Databases/Datasets, so any help would be great.

---

<div class="post-metadata">

**Author:** ![jespinmartin1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jespinmartin1/32/57175_2.png) [@jespinmartin1](https://forum.inductiveautomation.com/u/jespinmartin1)\
**Post date:** [October 19, 2021, 6:28am UTC](https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093/2 "2021-10-19T06:28:35Z")

</div>

This implementations looks familiar to me 😑  
This is not ethical @user39 , just to do it on your own.

“Clever” I should say, the way you set your username …

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [October 19, 2021, 12:18pm UTC](https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093/4 "2021-10-19T12:18:40Z")

</div>

As @jespinmartin1 stated, no help on the exams.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 19, 2021, 2:39pm UTC](https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093/5 "2021-10-19T14:39:17Z")

</div>

Oh, I didn’t realise it was part of the exam… It’s been a few years 😅. @jespinmartin1’s comment was very cryptic unless you knew that detail. Oh well

I guess the hint was in the “GoldSim”

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 19, 2021, 3:15pm UTC](https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093/6 "2021-10-19T15:15:03Z")

</div>

Closed on October 19, 2021, 3:15pm UTC



---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [October 19, 2021, 3:16pm UTC](https://forum.inductiveautomation.com/t/how-to-sort-a-json-for-a-flex-repeater/52093/7 "2021-10-19T15:16:47Z")

</div>

> [@system.db.runNamedQuery to execute between scripting](https://forum.inductiveautomation.com/t/system-db-runnamedquery-to-execute-between-scripting/47334/14):
>
> @jespinmartin1 is correct @nelson.hurtado. This is a question from the test, and as such, if you need help on the test, you need to email in to [training@inductiveautomation.com](mailto:training@inductiveautomation.com) for help. Help from other users on the forum is not allowed, as the test is meant to be a test of your efforts and not a group project.
