DemersM

arcpy.SetParameter() - Problem passing escaped string as geoprocessing service output

Discussion created by DemersM on Dec 19, 2016
Latest reply on Jan 19, 2017 by DemersM

I have a geoservice that get some text stored from a table in order to return a json string to a javascript client. However, the arcpy.SetParameter() seems to have problem to returns the escaped new lines character (\\n)

 

my_dict = {"key1" : "test is a string with\nsome escaped characters\nsuch newlines"} 
my_json
= json.dumps(my_dict)
print(my_json)
>>> '{"key1": "test is a string with\\nsome escaped characters\\nsuch newlines"}'

arcpy.SetParameter(0, my_json)

 

in the javascript console the response is the following which is not a valid json:

 

{"key1" : "test is a string with
some escaped characters
such newlines"
}

Is there a solution?

Outcomes