When click the send button, a validator will be triggered and I will check if the Dummy Json is right in syntax. Only the valid one will be sent to the server end. So, input like {{#repeat 2}} *** {{/rep} will not be sent to the server end.
As long as the syntax is valid, I will send it to the local server, then the Dummy JSON parser will generate random message(s) based on the template, namely, generate the {{int}}, {{repeat}} parts.
But since the Dummy Json parser can handle ordinary situations(including plain text), and we do not know what user really wants, so I can not check if the generated message is valid in JSON syntax. I mean, I can just use the Dummy JSON {{repeat}} to generate a list of random numbers but deliberately not in JSON format. e.g. [ {{repeat 3}} {{int 1 100}} {{/repeat}} ] => [1, 3, 10].
So, what I do next just follows the generally accepted practice:
If the message can be formated into JSON, and user does not explicitly asked to stringify it, the message will be sent as JSON Object.
If the message cannot be formated into JSON, either because it is a plain text(Hello world) or it is not a standard JSON format(maybe caused by syntax error, like {"a": "hello, the message will be sent as string, and the \n, \" will be shown in the message.
If the user explicitly asked to stringify the message, I will send it directly if it is a text, or I will do JSON.stringify() if it is a JSON Object and then send it.
Yes. And the procedure is as follows.
When click the send button, a validator will be triggered and I will check if the Dummy Json is right in syntax. Only the valid one will be sent to the server end. So, input like
{{#repeat 2}} *** {{/rep}
will not be sent to the server end.As long as the syntax is valid, I will send it to the local server, then the Dummy JSON parser will generate random message(s) based on the template, namely, generate the
{{int}}
,{{repeat}}
parts.But since the Dummy Json parser can handle ordinary situations(including plain text), and we do not know what user really wants, so I can not check if the generated message is valid in JSON syntax. I mean, I can just use the Dummy JSON
{{repeat}}
to generate a list of random numbers but deliberately not in JSON format. e.g.[ {{repeat 3}} {{int 1 100}} {{/repeat}} ]
=>[1, 3, 10]
.So, what I do next just follows the generally accepted practice:
Hello world
) or it is not a standard JSON format(maybe caused by syntax error, like{"a": "hello
, the message will be sent as string, and the\n
,\"
will be shown in the message.JSON.stringify()
if it is a JSON Object and then send it.