Page 1 of 1

Sending JSON to HTML template

Posted: 14 May 2018, 18:20
by elanvrt
It seems to be that we can send JSON data instead of XML to a HTML template with server 2.1.0.
This would be very useful, since I have a template that needs to receive 12 different strings.

Now I tried this, but CG ADD still requires an XML string to send some data to the update function.
i.e. CG 1-1 ADD 1 filename 0 "<xx>test</xx>"

Any info I found mentioned using the CasparCG client, but I do not use this, so I need the bare AMCP command to send JSON data.
Can anyone inform me on the secret code to send JSON data with CG ADD or CG UPDATE?

Re: Sending JSON to HTML template

Posted: 14 May 2018, 18:34
by balte
I have had no problems sending json to 2.1, what commands are you using?

Re: Sending JSON to HTML template

Posted: 15 May 2018, 10:11
by elanvrt
balte wrote:
14 May 2018, 18:34
I have had no problems sending json to 2.1, what commands are you using?
To begin with, the CG commands for 2.1 were until now never properly documented in the AMCP wiki, so I can only try things in the blind.

The only things that did not throw an error were something like:
-Bare JSON
CG 1-1 UPDATE 1 "{\"id\":\"Hello world\"}"
Only the "{" arrived in function update(str)

-JSON-in-XML
CG 1-1 UPDATE 1 "<templateData>{\"id\":\"Hello world\"}</templateData>"
Only the string "<templateData>{" arrived.

Looks like the string is chopped off on the \" escaped quote.
I also tried using single-quotes, then the JSON string arrives complete, but JSON.parse throws an error.

Can you please send me your example command, or -even better- refer a doc that reveals all those undocumented cg calls?

Also, do you know a method to make the 2.1 server console able to scroll back to more than the 100-something lines it shows now?
Often the info I seek is flying past before I can read it, because my automated client software sends a lot of commands in each cycle.
Reducing the log level is no good option, because logging the commands I send is an important debugging tool for me.

Re: Sending JSON to HTML template

Posted: 15 May 2018, 10:20
by mcdikki
The number of old lines in the console is not a casparCG setting but a cmd.exe setting in windows.
Right-click the windowbar of your console, goto Properties, choose tab Layout and increase the height of the windowbuffersize. That should give you a longer history.

cheers
mcdikki

Re: Sending JSON to HTML template

Posted: 15 May 2018, 12:12
by elanvrt
mcdikki wrote:
15 May 2018, 10:20
The number of old lines in the console is not a casparCG setting but a cmd.exe setting in windows.
Right-click the windowbar of your console, goto Properties, choose tab Layout and increase the height of the windowbuffersize. That should give you a longer history.

cheers
mcdikki
Thanks for the info. Too bad the defaults are not working. The console always opens with a buffer of 95 lines, no matter what the defaults are.

Re: Sending JSON to HTML template

Posted: 16 May 2018, 07:51
by balte
elanvrt wrote:
15 May 2018, 10:11
To begin with, the CG commands for 2.1 were until now never properly documented in the AMCP wiki, so I can only try things in the blind.
The CG commands didn't change much, if at all, AFAIK. Plus, the wiki has had 2.1 section for AMCP for years.
elanvrt wrote:
15 May 2018, 10:11
CG 1-1 UPDATE 1 "{\"id\":\"Hello world\"}"
This command works fine when I send it from the console.
elanvrt wrote:
15 May 2018, 10:11
CG 1-1 UPDATE 1 "<templateData>{\"id\":\"Hello world\"}</templateData>"
That's a workaround for 2.0.7, because it does not natively support sending JSON. (Technically, it only needs the first < sign) This is not needed in 2.1.0
elanvrt wrote:
15 May 2018, 10:11
Looks like the string is chopped off on the \" escaped quote.
I also tried using single-quotes, then the JSON string arrives complete, but JSON.parse throws an error.
This sounds a lot like you are not escaping the quotation marks properly. Can you try to check without any automation running and just sending the commands from the console, first.
elanvrt wrote:
15 May 2018, 10:11
Can you please send me your example command, or -even better- refer a doc that reveals all those undocumented cg calls?
I don't know of any CG commands that are not on these pages:
http://casparcg.com/wiki/CasparCG_2.1_A ... e_Commands
https://github.com/CasparCG/server/wiki ... e-commands
My example command would be the same as your first command :)
elanvrt wrote:
15 May 2018, 10:11
Also, do you know a method to make the 2.1 server console able to scroll back to more than the 100-something lines it shows now?
Often the info I seek is flying past before I can read it, because my automated client software sends a lot of commands in each cycle.
Reducing the log level is no good option, because logging the commands I send is an important debugging tool for me.
There are log files that you can read back.

Re: Sending JSON to HTML template

Posted: 16 May 2018, 12:44
by elanvrt
elanvrt wrote:
15 May 2018, 10:11
CG 1-1 UPDATE 1 "{\"id\":\"Hello world\"}"
This command works fine when I send it from the console.
elanvrt wrote:
15 May 2018, 10:11
Looks like the string is chopped off on the \" escaped quote.
I also tried using single-quotes, then the JSON string arrives complete, but JSON.parse throws an error.
This sounds a lot like you are not escaping the quotation marks properly. Can you try to check without any automation running and just sending the commands from the console, first.

Balte,

Thanks for the response.
I solved the escaping problem: I needed to "double-escape" the quote marks:
CG 1-1 UPDATE 1 "{\\\"id\\\":\\\"Hello world\\\"}"
But I'm gonna keep my previous workaround: Using single quotes in the command string, then replace them with double quotes in the update function, using this regexpression:

var jsonStr = str.replace(/'/g,"\"");