AnsweredAssumed Answered

JSON as toolbox parameter

Question asked by jay.kapalczynski on Mar 28, 2020
Latest reply on Apr 3, 2020 by jay.kapalczynski

I am trying to pass some record data from Javascript to GP Service which accepts one parameter

I want to grab this parameter on the python side and parse it to variables.


I am missing something here.....Having issues....

I can pass a string to the python script so that part works....

I am just unsure of I have to JSON string formatted properly before I pass it from Javascript

or if I am trying to parse it incorrectly on the python side.....these are the steps I am taking...




Step 1

Basically I am confused on how to create the JSON file on the javascript side....This will hold 3 records

I can format string to look like this and then set to JSON



var dict =  [  {'Results':
   ['address': 'some address', 'id': 'sone ID' , 'distance': 'some distance'],
   ['address': 'some address', 'id': 'sone ID' , 'distance': 'some distance'],
   ['address': 'some address', 'id': 'sone ID' , 'distance': 'some distance']
} ]

var dictstring = JSON.stringify(dict);

gp.execute(dictstring );


Step 2

I then need to pass this to a GP service I set up with an input parameter called '"Request"


When setting up the parameters do I select "STRING" ???




Step 3

import arcpy
import json

jsondata = arcpy.GetParameterAsText(0)

for each in jsondata[Results][0]:
   varId = (each['address'])
   varAddress = (each['id'])
   varDistance = (each['distance'])

   # do something with each of these record sets.