# Converting a dataset into a JSON file format for the flex repeater

**URL:** <https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 3, 2023, 6:40pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391 "2023-08-03T18:40:53Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mike\_Zylla](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_Zylla](https://forum.inductiveautomation.com/u/Mike_Zylla)\
**Post date:** [August 3, 2023, 6:40pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/1 "2023-08-03T18:40:53Z")

</div>

Hello,  
I have a dataset that i am first pulling from SQL, adding a column from a tag read, and then sorting. I want to get this into the Flex Repeater on perspective to allow it to show a view for every piece of equipment. The dataset is converted into a JSON in script.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/8/78cd1d698b948c56740d907beb9d9c05ee7fa83b.png)

However,, when i bind this to the Flex Repeater Instances object - it errors out.  
I am thinking there is an issue with how i am converting the dataset into a JSON, any ideas? It doesn't appear to have the right file format for the Flex Repeater - but i am unsure on how to get this format

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/4/141442e126678973c3aaaee5a657b1be53195ddb.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 3, 2023, 6:47pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/2 "2023-08-03T18:47:20Z")

</div>

The data you are giving to the instances prop appears to be coming out as a single dictionary, the instances prop expects an array(list of dictionaries), so you'll need to adjust your transform script to return your results as such.

You appear to be json encoding a dataset in your transform script, which will not return what you are looking for.

---

<div class="post-metadata">

**Author:** ![Mike\_Zylla](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_Zylla](https://forum.inductiveautomation.com/u/Mike_Zylla)\
**Post date:** [August 3, 2023, 6:49pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/3 "2023-08-03T18:49:29Z")

</div>

I have tried this - but it doesn't work either. It is like i am missing the column data?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/0/605ad139b2977adc27c042b1c0ea87f9f554fc2a.png)  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/a/b/ab4e51b04e7e8676edc8a080cc2c270d6c9ee446.png)

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 3, 2023, 6:50pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/4 "2023-08-03T18:50:18Z")

</div>

Post code - not pictures of code! That way we can copy it and edit in our answers. Format it using the \</\> button.

---

<div class="post-metadata">

**Author:** ![Mike\_Zylla](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_Zylla](https://forum.inductiveautomation.com/u/Mike_Zylla)\
**Post date:** [August 3, 2023, 6:54pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/5 "2023-08-03T18:54:35Z")

</div>

def transform(self, value, quality, timestamp):  
statusCol =   
newData =   
for row in range(value.getRowCount()):  
stationNumberInt = value.getValueAt(row,'station\_number')  
stationNumberStr = str(stationNumberInt)  
tagPath = '[default]ACME/Station '+stationNumberStr+ '/State .value' #Tag path for station  
status = system.tag.readBlocking(tagPath)[0].value #  
statusInt = int(status)  
#status = system.tag.readBlocking(tagPath)  
statusCol.append(status)

```
newData = system.dataset.addColumn(value,0,statusCol,'status',int)
sortedvalue = system.dataset.sort(newData, 'status', 1)
jsonData = system.util.jsonEncode(sortedvalue)
stationnumber = sortedvalue.getColumnAsList(1)

return stationnumber

```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 3, 2023, 6:58pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/6 "2023-08-03T18:58:19Z")

</div>

expected array item format is:

```auto
{
  "instanceStyle": {
    "classes": ""
  },
  "instancePosition": {},
  "param1": value,
  "param2": value2
}

```

if you don't care about the position properties or styles you can omit those.

Looking through your transform, a few things stand out other than the return format.

You have a line where you are building a tag path then immediately using a blocking read call to fetch the status of the machine. Consider instead passing this tag path to the flex instance as a parameter, and then having a custom property use this tag path in an indirect binding to fetch the tag value. Makes your transform simpler and faster.

Or if you must have the status value, consider using list comprehension to build the list of tag paths and use them in a single blocking read call.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 3, 2023, 7:08pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/7 "2023-08-03T19:08:58Z")

</div>

> [@Transistor](#):
>
> Format it using the \</\> button.

 ![Formatting code](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/0/70741738ea3cbbe8a2d249e1194c80035567335c.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 3, 2023, 7:09pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/8 "2023-08-03T19:09:59Z")

</div>

```auto
def transform(self, value, quality, timestamp):
	import operator

	statusValueTagPaths = ['[default]ACME/Station {0}/State'.format(value.getValueAt(x, 'station_number')) for x in xrange(value.rowCount)]
	statusValues = system.tag.readBlocking(statusValueTagPaths)

	repeaterItems = []
	positionDictionary = {}
	styleDictionary = {"classes": ""}

	for row in xrange(value.rowCount):
		stationNumber = value.getValueAt(row, 'station_number')
		repeaterItems.append({
			"instanceStyle": styleDictionary,
			"instancePosition": positionDictionary,
			"stationNumber": stationNumber,
			"stationTagPath": '[default]ACME/Station {0}/State'.format(stationNumber),
			"status": statusValues[row].value
		})

	repeaterItems.sort(key=operator.itemgetter("status"))

	return repeaterItems

```

This unfortunately loops over the base dataset twice (once for making tag paths and once for making the repeater items)

This is also complex enough of a transform that the script should be moved to a project level library and then called from the script transform.

@Transistor you need to find a way to make that reminder your signature

---

<div class="post-metadata">

**Author:** ![Mike\_Zylla](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_Zylla](https://forum.inductiveautomation.com/u/Mike_Zylla)\
**Post date:** [August 3, 2023, 7:45pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/9 "2023-08-03T19:45:26Z")

</div>

Thanks!

That looks like it should do the trick! I will give it a go when I am back at my computer

One question though - what does the “import operator” function do??

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 3, 2023, 8:01pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/10 "2023-08-03T20:01:50Z")

</div>

Its just a library import. That is just so I can use the `operator.itemgetter('key')` function to use as the sort key for sorting the final array. It is supposed to be more performant/straightforward than making a `lambda` call.

---

<div class="post-metadata">

**Author:** ![Mike\_Zylla](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_Zylla](https://forum.inductiveautomation.com/u/Mike_Zylla)\
**Post date:** [August 3, 2023, 9:44pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/11 "2023-08-03T21:44:58Z")

</div>

Makes sense - trying to work with it a bit, but for whatever reason it isn't reading the status value it - as they are all null, so the sort function doesn't work.  
Any ideas?  
I have been working with it - but to be honest, don't quite understand why the tag isn't reading - since the path is correct.

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/a/7a26bbe68ddce96cf4d9b2febcc93157875e486b.png)

Code here: `def transform(self, value, quality, timestamp):  
import operator

```
statusValueTagPaths = ['[default]ACME/Station {0}/State'.format(value.getValueAt(x, 'station_number')) for x in xrange(value.rowCount)]
statusValues = system.tag.readBlocking(statusValueTagPaths)

		
repeaterItems = []
positionDictionary = {}
styleDictionary = {"classes": ""}

for row in xrange(value.rowCount):
	stationNumber = value.getValueAt(row, 'station_number')
	repeaterItems.append({
			"instanceStyle": styleDictionary,
			"instancePosition": positionDictionary,
			"stationNumber": stationNumber,
			"stationTagPath": '[default]ACME/Station {0}/State '.format(stationNumber),
			"status": statusValues[row].value
		})

repeaterItems.sort(key=operator.itemgetter("status"))

return repeaterItems`

```

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 3, 2023, 10:03pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/12 "2023-08-03T22:03:31Z")

</div>

You have a space at the very end of the tag path, does your tag actually have a space at the end of its name? That seems like it would be a typo rather than a naming convention.

You can test if the tag path is valid by copying one of them and then setting a custom test property to be a tag binding with the copied path.

Edit:

> [@Mike\_Zylla](#):
>
> `statusValueTagPaths = ['[default]ACME/Station {0}/State'.format(value.getValueAt(x, 'station_number')) for x in xrange(value.rowCount)]`

should be

```auto
statusValueTagPaths = ['[default]ACME/Station {0}/State '.format(value.getValueAt(x, 'station_number')) for x in xrange(value.rowCount)]

```

You only adjusted one of the tag paths to include the space at the end

---

<div class="post-metadata">

**Author:** ![Mike\_Zylla](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_Zylla](https://forum.inductiveautomation.com/u/Mike_Zylla)\
**Post date:** [August 3, 2023, 10:35pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/13 "2023-08-03T22:35:34Z")

</div>

Wow, i just saw that...  
I screwed up when i made the UDT, and didn't catch it till now. Ugh - debating on changing the script or going back and finding all of the references....

Anyways - that you for all of your help - i really appreciate it!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 3, 2023, 10:43pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/14 "2023-08-03T22:43:08Z")

</div>

> [@ryan.white](#):
>
> This unfortunately loops over the base dataset twice (once for making tag paths and once for making the repeater items)

Here is a version that doesn't loop through the dataset twice.

```python
def transform(self, value, quality, timestamp):
	import operator

	statusValueTagPaths = ['[default]ACME/Station {0}/State'.format(row['station_number']) for row in system.dataset.toPyDataSet(value)]
	statusValues = system.tag.readBlocking(statusValueTagPaths)

	repeaterItems = [{
			"instanceStyle": {'classes':''},
			"instancePosition": {},
			"stationNumber": path.split('/')[1][-1:],
			"stationTagPath": path,
			"status": statusValues[index].value
		} for index,path in enumerate(statusValueTagPaths)]

	repeaterItems.sort(key=operator.itemgetter("status"))

	return repeaterItems

```

---

<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:** [August 3, 2023, 11:52pm UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/15 "2023-08-03T23:52:51Z")

</div>

ACME... this looks like a certification question... what is it with people trying to flout the rules lately?? I do wonder if these certs get thrown out or do they just a slap on the wrist with no consequence?

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 4, 2023, 12:12am UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/16 "2023-08-04T00:12:26Z")

</div>

I sure hope not, I wouldn’t know as I’ve never taken it.

Ugh, almost need to take it so I know.

---

<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:** [August 4, 2023, 12:14am UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/17 "2023-08-04T00:14:26Z")

</div>

Yeah, ACME and "Station" are ringing major alarm bells to me, as these were a big part of the practical side. It's been a few years since I did mine though. I've been caught out in some of the recent posts that were taken down, as I didn't recognise them as from the certs. They must have updated them or my memory is failing.

It CLEARLY states it in the cert info though that asking questions on the forum is prohibited

Edit: This is from when I did my cert. Maybe it doesn't mention the forum, but it's pretty darn obvious you shouldn't be using it (or the help from peers, for that matter either)  
Maybe this wording has changed and is less explicit??  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/9/89a975a032c18f04d0331b84dabe89c941307f6d.png)

Edit2:  
@Mike_Zylla This from a RECENT cert info sheet, and again, clearly states in no uncertain terms where you can get help from... It also states the repercussions of trying to flout the rules. I'm not sure how someone would think it's ok to try to cheat on a certification test? If you get help from _anyone_ else, it's not proving that **you**'re capable; it's proving that the **other** person is capable

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/0/c0145cad70a31d5e9fefd819fd7bc5e5f5a05dcc.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 4, 2023, 12:44am UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/18 "2023-08-04T00:44:16Z")

</div>

Good to know I won't have any issue with that part of the cert then.

---

<div class="post-metadata">

**Author:** ![Mike\_Zylla](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@Mike\_Zylla](https://forum.inductiveautomation.com/u/Mike_Zylla)\
**Post date:** [August 4, 2023, 12:52am UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/19 "2023-08-04T00:52:30Z")

</div>

The exam says you cannot receive help from the IA Support group, not the forum

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [August 4, 2023, 1:19am UTC](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391/20 "2023-08-04T01:19:13Z")

</div>

Well, as I understand it it won’t matter for much longer as they’re going to phasing out the tests, if I remember correctly.

[Next page](https://forum.inductiveautomation.com/t/converting-a-dataset-into-a-json-file-format-for-the-flex-repeater/77391.md?page=2)
