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:
<SPAN class="keyword token">import</SPAN> os
<SPAN class="keyword token">import</SPAN> arcpy
<SPAN class="keyword token">import</SPAN> uuid
<SPAN class="comment token">#GP tool input parameter</SPAN>
inSessionStr <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>GetParameterAsText<SPAN class="punctuation token">(</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#write a to a temp .json file (taken from the enhanced print service blog</SPAN>
output <SPAN class="operator token">=</SPAN> <SPAN class="string token">'SessionFile_{}.{}'</SPAN><SPAN class="punctuation token">.</SPAN>format<SPAN class="punctuation token">(</SPAN>str<SPAN class="punctuation token">(</SPAN>uuid<SPAN class="punctuation token">.</SPAN>uuid1<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"json"</SPAN><SPAN class="punctuation token">)</SPAN>
Output_File <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>arcpy<SPAN class="punctuation token">.</SPAN>env<SPAN class="punctuation token">.</SPAN>scratchFolder<SPAN class="punctuation token">,</SPAN> output<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#write to the .json file</SPAN>
outputSessionfile <SPAN class="operator token">=</SPAN> open<SPAN class="punctuation token">(</SPAN>Output_File<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">'w'</SPAN><SPAN class="punctuation token">)</SPAN>
outputSessionfile<SPAN class="punctuation token">.</SPAN>write<SPAN class="punctuation token">(</SPAN>inSessionStr<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#specify the output parameter as the outputSession file</SPAN>
arcpy<SPAN class="punctuation token">.</SPAN>SetParameter<SPAN class="punctuation token">(</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">,</SPAN> outputSessionfile<SPAN class="punctuation token">)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Any ideas on if this might work and what to look for?