ENCODEJSON() similar to ENCODEURL()

Similar to how ENCODEURL() encodes characters to be able to be used on context where HTML values could break the code, we need ENCODEJSON() so that we don't need to manually do it inside JSON body templates on webhooks.

It's a pain to check for this manually eventhough I use VSCode to transform to a JSON String.

BUT! What if your content is generated dynamically with expressions and you also need that content to be encoded?

1 Comment
Axel_Pro
Silver 1
Silver 1

 

+1 support the idea!

Required function in AppSheet similar JS:

 

JSON.stringify()

 

Syntax:

 

ENCODEJSON("key", "value", "key2", "value2", ...) 
OR 
JSONSTRINGIFY("key", "value", "key2", "value2", ...)

 

Result:

 

"{"key": "value","key2": "value2"}"

 

Now you have to do this with the help of complex manipulations (example):

 

CONCATENATE(
"{", 
CONCATENATE("""entity"":", """", "Product", """", ","),
CONCATENATE("""ID"":", [ID], ","),
CONCATENATE("""name"":", """", SUBSTITUTE([name], """", "\"""), """", ","),
CONCATENATE("""SKU"":", """", [SKU], """", ","),
CONCATENATE("""short_name"":", """", SUBSTITUTE([short_name], """", "\"""), """", ","),
CONCATENATE("""FK_key"":", """", SUBSTITUTE([FK_key], """", "\"""), """"),
"}"
)

 

The implementation of the function will greatly simplify the interaction of AppSheet with external services (API) where JSON is used as the data exchange format (for example, to send information to print)