AnsweredAssumed Answered

NumPy 'ValueError: size of tuple must match number of fields.'

Question asked by geoffreywestgis on Feb 14, 2015
Latest reply on Feb 16, 2015 by Dan_Patterson

I have a script which parses an json web-service and uses parses the fields to add to a file geodatabase, towards the end of my script I receive the error. I receive the error

File "C:/Python27/ArcGIS10.2/websocket-client-0.23.0/websocket-client-0.23.0/examples/", line 43, in     narr = numpy.array([vehicles],  ndtype) ValueError: size of tuple must match number of fields.


import json
import jsonpickle
import requests
import arcpy
import numpy

fc = "C:\MYLATesting.gdb\MYLA311"
if arcpy.Exists(fc):

f = open('C:\Users\Administrator\Desktop\myla311.json', 'r')

data = jsonpickle.encode( jsonpickle.decode( )

url = ""
headers = {'Content-type': 'text/plain', 'Accept': '/'}

r =, data=data, headers=headers)
sr = arcpy.SpatialReference(4326)

decoded = json.loads(r.text)

SRAddress = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['SRAddress']
latitude = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['Latitude']
longitude = decoded['Response']['ListOfServiceRequest']['ServiceRequest'][0]['Longitude']

a = {"items":[{SRAddress, latitude, longitude}]}

ndtype = numpy.dtype([
  ('SRAddress', 'S16'),
   ('latitude', 'F48'),
   ('longitude', 'F48')


vehicles = []
for item in a['items']:
  vehicles.append(tuple(unicode(item[k] for k in ndtype.names)))
narr = numpy.array([vehicles], ndtype)
arcpy.da.NumPyArrayToFeatureClass(narr, fc, ['longitude', 'latitude'], sr)

print a.keys()

# parsed_json = json.dumps(decoded, sort_keys=True, indent=4)

# print json.dumps(decoded, sort_keys=True, indent=4)