# SOAP - convert Python dictionary to tabel

**URL:** <https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527>\
**Category:** Ignition\
**Created:** [March 28, 2018, 1:44am UTC](https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527 "2018-03-28T01:44:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shc/32/4918_2.png) [@shc](https://forum.inductiveautomation.com/u/shc)\
**Post date:** [March 28, 2018, 1:44am UTC](https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527/1 "2018-03-28T01:44:31Z")

</div>

When using SOAP to recipe a message from our ERP, I get a dictionary header that looks like this

{“Root”: {“ReadMultiple\_Result”: {“ReadMultiple\_Result”: {“employ”: [  
{  
“Comment”: false,  
“First\_Name”: “Piranan”,  
“FullName”: “Piranan Sriratya”,  
“Initials”: “HJA”,  
“Job\_Title”: “Accounting”,  
“Key”: “20;UBQAAAJ7BDAAMA0wADE=7;87293340;”,  
“Last\_Name”: “Sriratya”,  
“Mobile\_Phone\_No”: “0891557097”,  
“No”: “0001”,  
“Phone\_No”: “0891557807”,  
“Resource\_No”: “0001”,  
“Search\_Name”: “NAN”  
},

I’m trying to convert it into a table, like this

def dictToDataset(dictValue):  
data = []   
columns = dictValue[“employ”][0].keys()  
for obj in dictValue[“Root”]:  
row = []  
for column in columns:  
#print(column)  
row.append(obj[column])  
data.append(row)  
return system.dataset.toDataSet(columns,data)

table = event.source.parent.getComponent(‘Table’)  
wsrespons = system.ws.runWebService(‘testt’)  
Dic = system.ws.toDict(wsrespons)  
table.data = dictToDataset(Dic)

If I manuel edit the header to just contain “employ” then it working ok, but how to get the key from the original respons, ?

---

<div class="post-metadata">

**Author:** ![phillip.bow](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phillip.bow](https://forum.inductiveautomation.com/u/phillip.bow)\
**Post date:** [March 28, 2018, 3:14pm UTC](https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527/2 "2018-03-28T15:14:29Z")

</div>

Is that the actual text of the response you get? It looks more like JSON than a SOAP response so if that is it you should be able to do:

```auto
data = """
{
	"Root": {
		"ReadMultiple_Result": {
			"ReadMultiple_Result": {
				"employ": [{
					"Comment": false,
					"First_Name": "Piranan",
					"FullName": "Piranan Sriratya",
					"Initials": "HJA",
					"Job_Title": "Accounting",
					"Key": "20;UBQAAAJ7BDAAMA0wADE=7;87293340;",
					"Last_Name": "Sriratya",
					"Mobile_Phone_No": "0891557097",
					"No": "0001",
					"Phone_No": "0891557807",
					"Resource_No": "0001",
					"Search_Name": "NAN"
				}]
			}
		}
	}
}
"""

js = system.util.jsonDecode(data)

print js['Root']['ReadMultiple_Result']['ReadMultiple_Result']['employ'][0]

```

---

<div class="post-metadata">

**Author:** ![shc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shc/32/4918_2.png) [@shc](https://forum.inductiveautomation.com/u/shc)\
**Post date:** [March 29, 2018, 8:52am UTC](https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527/3 "2018-03-29T08:52:46Z")

</div>

> [@phillip.bow](#):
>
> js = system.util.jsonDecode(data)
> 
> print js['Root']['ReadMultiple\_Result']['ReadMultiple\_Result']['employ'][0]

Hi, yes, I get the data in via sepasoft soap web service,,, but it decodes fine with your suggestion, thanks :-):

---

<div class="post-metadata">

**Author:** ![shc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shc/32/4918_2.png) [@shc](https://forum.inductiveautomation.com/u/shc)\
**Post date:** [March 29, 2018, 9:57am UTC](https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527/4 "2018-03-29T09:57:11Z")

</div>

My final code, reading from Dynamic Navision2013, reading employee list via sepasoft web service

def dictToDataset(dictValue):  
data = []   
columns = dictValue[‘Root’][‘ReadMultiple\_Result’][‘ReadMultiple\_Result’][‘employ’][0].keys()

```
i = 0
for obj in dictValue['Root']['ReadMultiple_Result']['ReadMultiple_Result']['employ']:
			
	row = []
	for column in columns:
		
		if column in dictValue['Root']['ReadMultiple_Result']['ReadMultiple_Result']['employ'][i].keys():
	      		row.append(obj[column])
	 	else:
	      		row.append("")
	   
	data.append(row)
	i = i + 1
return system.dataset.toDataSet(columns,data)

```

table = event.source.parent.getComponent(‘Table’)

wsrespons = system.ws.runWebService(‘employ’)  
string = wsrespons.toString()  
js = system.util.jsonDecode(string)

table.data = dictToDataset(js)

---

<div class="post-metadata">

**Author:** ![phillip.bow](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phillip.bow](https://forum.inductiveautomation.com/u/phillip.bow)\
**Post date:** [March 29, 2018, 3:07pm UTC](https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527/5 "2018-03-29T15:07:30Z")

</div>

Ah I see I’ve led you astray a bit in this regard since the Sepasoft webservice request converts the SOAP response into a JSON-ish looking structure when stringified.

If you’re willing to play with it a bit more you can probably simplify your code and reduce a lot of the processing needed by doing something more like this:

```auto
table = event.source.parent.getComponent('Table')

wsrespons = system.ws.runWebService('employ')
root = wsresponse.getChild("Root")
r1 = root.getChild("ReadMultiple_Result")
r2 = f1.getChild("ReadMultiple_Result")
employees = r2.getChild("employ")
table.data = employees.toDataSet()

```

---

<div class="post-metadata">

**Author:** ![shc](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/shc/32/4918_2.png) [@shc](https://forum.inductiveautomation.com/u/shc)\
**Post date:** [March 30, 2018, 3:40am UTC](https://forum.inductiveautomation.com/t/soap-convert-python-dictionary-to-tabel/17527/6 "2018-03-30T03:40:09Z")

</div>

I played a bit, and the concept is brilliant  
But it looks like there is only 1 child, ☹

made a small script to test the file

wsrespons = system.ws.runWebService(‘employlist’)  
root = wsrespons.hasChildren()  
print root  
root = wsrespons.getChildCount()  
print root  
root = wsrespons.getName()  
print root

Output:  
True  
1  
Root
