Page 1 of 1

Need Clarification on JSON String Formatting Error

Posted: June 30th, 2025, 12:39 pm
by khurshid.arshad
Dear Team,

I hope this message finds you well.

I am currently using the following lines of code, but I encountered the error.

function numeric ViewQuestionnaire(string dictionary_name="CEN2000")

setfile(CEN2000, "..\103 - Data\Census_data.csdb");

string cen2000_directory = "C:\214 - YouTube CSPro - syntime\100 - SyncTimeApp" ;
string cen2000_form_path = Path.concat(cen2000_directory, "102 - Popstan Census", "Census Data Entry.fmf");
string cen2000_qsf_path = Path.concat(cen2000_directory, "102 - Popstan Census", "Census Data Entry.ent.qsf");

string questionnaireViewInput =
maketext("{ \"dictionary\": %s, \"forms\": %s, \"questionText\": %s, \"case\": %s }",
CS.Dictionary.getDictionary(name := "CEN2000"),
CS.Application.getFormFile(path := cen2000_form_path),
CS.Application.getQuestionText(path := cen2000_qsf_path),
CS.Data.getCase(name := "CEN2000", key :="010101301520130191"));

CS.UI.view(path := Path.concat(html, "questionnaire-view", "index.html"),
inputData := @object questionnaireViewInput);

end;

ERROR(ViewQuestionnaire, 305): 'dictionary\"' is not a declared variable or is a misspelled dictionary entry


However, when I removed the backslash (\), the code executed successfully.

function numeric ViewQuestionnaire(string dictionary_name="CEN2000")

setfile(CEN2000, "..\103 - Data\Census_data.csdb");

string cen2000_directory = "C:\214 - YouTube CSPro - syntime\100 - SyncTimeApp" ;
string cen2000_form_path = Path.concat(cen2000_directory, "102 - Popstan Census", "Census Data Entry.fmf");
string cen2000_qsf_path = Path.concat(cen2000_directory, "102 - Popstan Census", "Census Data Entry.ent.qsf");

string questionnaireViewInput =
maketext('{"dictionary": %s, "forms": %s, "questionText": %s, "case": %s}',
CS.Dictionary.getDictionary(name := "CEN2000"),
CS.Application.getFormFile(path := cen2000_form_path),
CS.Application.getQuestionText(path := cen2000_qsf_path),
CS.Data.getCase(name := "CEN2000", key :="010101301520130191"));

// // pass this input to the questionnaire view
CS.UI.view(path := Path.concat(html, "questionnaire-view", "index.html"),
inputData := @object questionnaireViewInput);

end;

Could you please confirm if this is the correct approach, or let me know if there is an issue with my code?

Thank you for your support.

Best regards,
a.

Re: Need Clarification on JSON String Formatting Error

Posted: July 1st, 2025, 8:19 am
by Gregory Martin
It looks like this is because you are using the original logic version: https://www.csprousers.org/help/CSPro/l ... rsion.html

In that version, using a backslash does not signal that you are specifying an escape sequence. Notice the difference in how the strings are colored:
{  version: original } maketext("{ \"dictionary\"...MORE STRING CONTENT...
/* version: 8.0+    */ maketext("{ \"dictionary\"...MORE STRING CONTENT...
That is why you are getting the error message about dictionary, because CSPro is trying to parse dictionary as the second argument to the maketext function.

It's clear that you're using the original version because of your paths. You write:
string cen2000_directory = "C:\214 - YouTube CSPro - syntime\100 - SyncTimeApp";
But in the logic version introduced in CSPro 8.0, you would have to escape the backslash characters:
string cen2000_directory = "C:\\214 - YouTube CSPro - syntime\\100 - SyncTimeApp";
We're slowly trying to modernize CSPro, and this logic version was introduced in part so that escape sequences could be used in CSPro. Among other things, this helps with using newlines: https://www.csprousers.org/help/CSPro/n ... dling.html

Re: Need Clarification on JSON String Formatting Error

Posted: July 1st, 2025, 11:30 am
by khurshid.arshad
Dear Gregory;

I hope you are doing well.

As per your instructions, after make selection from Orignal to CSPro 8.0+ in {Options->Application Properties->Logic Settings}, it is now working.

Please give my regards to the team,

take care, and thank you.
A.