# Pulling Data From JSON

**URL:** <https://forum.inductiveautomation.com/t/pulling-data-from-json/37433>\
**Category:** Ignition\
**Created:** [August 5, 2020, 9:56pm UTC](https://forum.inductiveautomation.com/t/pulling-data-from-json/37433 "2020-08-05T21:56:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasonstrunk](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jasonstrunk](https://forum.inductiveautomation.com/u/jasonstrunk)\
**Post date:** [August 5, 2020, 9:56pm UTC](https://forum.inductiveautomation.com/t/pulling-data-from-json/37433/1 "2020-08-05T21:56:46Z")

</div>

I’m having some issues pulling data from a JSON object. The code is:

```auto
receivedData=system.net.httpGet("http://192.168.1.49/api/setpoints/refrigeration/")
print receivedData
DataJSON=system.util.jsonDecode(receivedData)
print DataJSON
for i in DataJSON["RoomTemp"]:
	print i["currentValue"]

```

The error I’m getting is regarding the print command in the for loop.

```auto
Traceback (most recent call last):
  File "<input>", line 6, in <module>
TypeError: unicode indices must be integers

```

My (simplified) outputs are:

```auto
print receivedData
{
	"RoomTemp":{
		"current":"6.0 F",
		"currentValue":"6.0",
		"units":"F"
	}
}

print DataJSON
{u'RoomTemp': {u'units': 'F', u'current': '6.0 F', u'currentValue': '6.0'}}

```

Any help would be greatly appreciated.

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [August 5, 2020, 10:10pm UTC](https://forum.inductiveautomation.com/t/pulling-data-from-json/37433/2 "2020-08-05T22:10:47Z")

</div>

In Python, iterating through a dictionary will get you the key names. You can then use these key names to get the values you’re looking for out of the dictionary.

Here’s one option:

```auto
DataJSON = {u'RoomTemp': {u'units': 'F', u'current': '6.0 F', u'currentValue': '6.0'}}
for key in DataJSON:
	try:
		print DataJSON[key]['currentValue']
	except:
		pass

```

And here’s another:

```auto
DataJSON = {u'RoomTemp': {u'units': 'F', u'current': '6.0 F', u'currentValue': '6.0'}}
for key in DataJSON:
	valueString = 'currentValue'
	currentValue = DataJSON[key][valueString] if valueString in DataJSON[key] else None
	print currentValue

```

---

<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:** [August 5, 2020, 10:19pm UTC](https://forum.inductiveautomation.com/t/pulling-data-from-json/37433/3 "2020-08-05T22:19:54Z")

</div>

Yep, there are lots of options to iterate through dictionaries. You can go through just the values:

```auto
for room in DataJSON.values():
    print room["currentValue"]

```

Just the keys:

```auto
for key in DataJSON.keys(): #or leave the .keys() off entirely
    print DataJSON[key]["currentValue"]

```

Or both the key and value together:

```auto
for key, value in DataJSON.items():
     print key
     print value["currentValue"]

```

---

<div class="post-metadata">

**Author:** ![jasonstrunk](https://avatars.discourse-cdn.com/v4/letter/j/a88e4f/32.png) [@jasonstrunk](https://forum.inductiveautomation.com/u/jasonstrunk)\
**Post date:** [August 5, 2020, 10:40pm UTC](https://forum.inductiveautomation.com/t/pulling-data-from-json/37433/4 "2020-08-05T22:40:45Z")

</div>

Thank you. This was extremely helpful.

---

<div class="post-metadata">

**Author:** ![krunallathiya21.kl](https://avatars.discourse-cdn.com/v4/letter/k/e0b2c6/32.png) [@krunallathiya21.kl](https://forum.inductiveautomation.com/u/krunallathiya21.kl)\
**Post date:** [August 27, 2020, 6:26am UTC](https://forum.inductiveautomation.com/t/pulling-data-from-json/37433/5 "2020-08-27T06:26:52Z")

</div>

The **dictionary keys()** method in Python returns a view object that displays a list of all the keys in the dictionary.

The **dictionary values()** method returns a view object. The view object contains the values of the dictionary, as a list. The view object will reflect any changes done to the dictionary.

The **dictionary items()** method is used to return the list with all dictionary **keys** with **values**.

These are the basic definitions of above answers.

I hope this helps,
