How to decode script written in RunJavaScript Server Action

I want to use below line in RunJavaScript action. 

If not encoded, Then running properly( [{\\\"JsonKey\\\": ). But how can I achieve it by using EncodeJavaScript().

EncodeJavaScript("new BuildMyMap('" + map.Id + "', " + JSON_data + ", '" + TypeId +"')")


JSON_data: is a variable with json data, 

When I use EncodeJavaScript() then its converting quotes of json as usual 

( \\\\x27, [{\\\\x22JsonKey\\\\x22: ). So its not calling the BuildMyMap() function properly.



Solution

You will want to only use EncodeJavaScript on your JSON_data instead.

The goal is to sanitize your JSON data right? Why would you encode your entire script? 

Solution

Joey Moree wrote:

You will want to only use EncodeJavaScript on your JSON_data instead.

The goal is to sanitize your JSON data right? Why would you encode your entire script? 

OS is showing warning for that... Ensure the expression is protected by EncodeJavaScript()..


I also tried to encode only JSON_data, still same issue

Joey Moree wrote:

You will want to only use EncodeJavaScript on your JSON_data instead.

The goal is to sanitize your JSON data right? Why would you encode your entire script? 


 Thanks Joey, 

Following line worked properly:

"new BuildMyMap('" + map.Id + "', " + EncodeJavaScript(JSON_data) + ", '" + TypeId +"')"