AnsweredAssumed Answered

GP Service Ideas to output a .json file

Question asked by jamesfreddyc on Sep 21, 2017
Latest reply on Sep 21, 2017 by jamesfreddyc

EDIT: Turns out the .py script example I have below does actually create the .json file with the input parameter value.  I'm just not correctly handling the JavaScript side to allow user to "SaveAs".

 

Wild idea but *should be* straight forward.  I'd like to publish a GP service that simply takes an input string (well formatted json), write that string to a .json file (just a text file would do with a .json extension I think) and set this to an output parameter.

 

What I have so far doesn't error out but also doesn't seem to generate the output .json I'm expecting.

 

Simple python script source to the GP tool:

 

import os
import arcpy
import uuid

#GP tool input parameter
inSessionStr = arcpy.GetParameterAsText(0)

#write a to a temp .json file (taken from the enhanced print service blog
output = 'SessionFile_{}.{}'.format(str(uuid.uuid1()), "json")
Output_File = os.path.join(arcpy.env.scratchFolder, output)

#write to the .json file
outputSessionfile = open(Output_File, 'w')
outputSessionfile.write(inSessionStr)

#specify the output parameter as the outputSession file
arcpy.SetParameter(1, outputSessionfile)

 

Any ideas on if this might work and what to look for?

Outcomes