Parse a json as a variable in an agi scripts

When I parse a json as a variable value in an agi script, asterisk removes the double quotes.

The variable is not usable any more with the funciton json_decode.

How can I keep the orginal format and make the variable usable as json inside the dialplan.

I have tried to put quotes (single and double around it) but nothing helps.

<PJSIP/telserv-00019d8d>AGI Rx

<< SET VARIABLE “CHATPPMSTART” “‘{“status”: “NOK”, “code”: “123456”, “access”: “NO”}’”

<PJSIP/telserv-00019d8d>AGI Tx >> 200 result=1
‘{status: NOK, code: 123456, access: NO}’
[2026-03-31 13:57:36] WARNING[3703250][C-00015df0]: func_json.c:111 json_decode_read: Failed to parse as JSON: ‘{status: NOK, code: 123456, access: NO}’

I found a solution for this.

In het python agi script:

agi.set_variable(“keyjson”, valuejson.replace(‘“’,‘\\”’))

(basicly backslash the double quote, this keeps the json format)

1 Like