How to insert json in custom cdr field

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

Apologies, I didn’t read the full code.

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.

Please use 'Preformatted text' tags when posting snippets.

Should this be '${data}'?

My PHP (7.2.19) complains about both.

If you enable 'agi set debug on' you should be able to see what is being sent to Asterisk and returned by Asterisk. This may yield clues :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.