I want to insert a json format in custom cdr field which i have made but when i try to save it is stored in simple string rather than json format like
$data = [‘data’ => [‘value’=>1234, ‘time’ => time()]];
$data= json_encode($data);
$agi->exec(‘set’,“cdr(custom_field)= {$data}”);
but the data which is store in database is different its like
{data:{value:1234,time:21-09-2020}} and i want this in
{“data”: {“value” : “1234”, “time” : “21-09-2020”}}
any help is helpful
This is a question relating to the host language for your AGI script, not an Asterisk one. Typically you would need to put the whole expression into some form of quote marks, probably double quotes.
i have tried that thing but its not working i just want to know
$agi->exec(‘set’,“cdr(custom_field)= {$data}”);
this thing is right ? because it treats as a string
Firstly: I don’t understand why you are doing this in a roundabout way, rather than using AGI’s set variable command.
Actually, I think that is the secondly as well! You are passing the JSON through a lot of text processing, which probably will strip quotation marks. I can’t promise that using the proper AGI command will be quotation mark safe, but it is more likely to be.
Note that functions can appear on the left of an assignment in most or all places where asterisk allows a variable.