# JSON to Ignition Dataset

**URL:** <https://forum.inductiveautomation.com/t/json-to-ignition-dataset/82274>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 23, 2023, 12:32am UTC](https://forum.inductiveautomation.com/t/json-to-ignition-dataset/82274 "2023-11-23T00:32:49Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [November 24, 2023, 3:06pm UTC](https://forum.inductiveautomation.com/t/json-to-ignition-dataset/82274/4 "2023-11-24T15:06:54Z")

</div>

Just having a bit of fun on my computer, I was able to convert your results to a dataset using this script:

```auto
# filepath = wherever your file is stored

# Get the file as a string
jsonString = system.file.readFileAsString(filepath)

# Load the file as a json object
jsonFile = system.util.jsonDecode(jsonString)

# Get the first key of the results as a reference for getting the headers and iteration lengths
firstKey = next(iter(jsonFile['results']))

# Get the headers from the first key's keys
headers = jsonFile['results'][firstKey].keys()

# "data =" could be done with comprehension, but nested comprehensions can get convoluted
# Initialize a data list for or the row lists that will comprise the data in the dataset
data = []

# Iterate over the indexes of the first value list in the 'results' dictionary
for index in range(len(next(iter(jsonFile['results'][firstKey].values())))):
	
	# For each key in the 'results' dictionary
	for key in jsonFile['results'].keys():
	
		# Create a row by extracting the 'index'-th element from each value list
		rowData = [value[index] for value in jsonFile['results'][key].values()]
		
		# Append the created row to the 'data' list
		data.append(rowData)
		
# Convert the headers and data into a dataset
dataset = system.dataset.toDataSet(headers, data)

```

**Result:**

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/6/26db65da879f0c1766d5f8121728939fe1796d83.png)

---

_[View the full topic](https://forum.inductiveautomation.com/t/json-to-ignition-dataset/82274)._
