There is a reason why the function takes a variable name, not the actual JSON string. You have defeated that by trying to set a variable from the actual JSON string, in preceding line.
Whilst in general, this question is unanswerable without the exact contents of the JSON string, my guess is that you will find that it contains dialplan syntax delimiter characters.
Note that, if some parts of it don’t come from a totally trustworthy source, you may have a code injection vulnerability. Thinking further, the dialplan misparses possible here may be enough to execute anything harmful.
The reason that assigning to a variable could go wrong is that Asterisk dialplans are really text macros, and the values of variables are physically substituted into the dialplan line, and that is what gets parsed and passed to the application.
If you run the first version at at least verbosity 3, you should see the actual set application parameters.
This is because the dialplan interpreter is really a macro processor. The variable is substituted without reference to the quotation marks. If there is an isolated " in the variables value, the expression evaluator sees
"....."....." = ""
and thinks the = is in quotes.
Expressions are handled by a formal grammar, whereas most of the dialplan, and application arguments, is handled with more ad hoc parsing. There is is a lexical rule:
which treats any string of characters starting and ending with ", but not containing one, on a left to right scan, as being a string. Potential operator characters within one are not recognized as such.
Extensions register to receive calls, there is no such thing as a SIP login. for chan_pjsip, that information comes under the heading of contacts. For chan_sip, it was called users.
I suspect your list of fields is taken from the FreePBX database, which is mainly used to construct the Asterisk configuration files, which are, in turn, read into memory by Asterisk. The existence of registrations is only normally recorded in memory (there may be some provision for persistence, but that is done by Asterisk, and FreePBX won’t record it).