SQL Question with Random inputs(bug)

SQL Question with Random inputs(bug)

de Daniel Buchberger -
Número de respuestas: 4

I have created a nice randomized SQL-Question but the TWIG template I wrote didn'T match as JSON-String. But on this side: https://twigfiddle.com/a3m2t3

I get no fault.

I think something went wrong, maybe someone can help me?

I put my code in the attachment.

Greez buchi

Marcas:
En respuesta a Daniel Buchberger

Re: SQL Question with Random inputs(bug)

de Richard Lobb -
JSON strings can't contain newline characters; they should be represented as '\n'.

This leads to long lines, hard to maintain in the question authoring form. But I don't have a simple solution, except perhaps to write the template preprocessor in python (if you have an up to date coderunner). But that introduces a risk of jobe server overload if you're using the question in tests or exams with large classes.
En respuesta a Richard Lobb

Re: SQL Question with Random inputs(bug)

de Daniel Buchberger -

Thank you for your help, but why is this(attached file) now still wrong...in Coderunner not in Twig fiddle and json validator...

En respuesta a Daniel Buchberger

Re: SQL Question with Random inputs(bug)

de Richard Lobb -

The template parameters must be valid JSON or, if you are using a preprocessor like Twig, must evaluate to valid JASON. If I paste your twig code into twigfiddle.com I get output like:

{
    "frage": "Vorname lautet Ryan",
    "sql": "Vorname <> 'Ryan'",
    "out": "1 Melissa Andrews
    2 Miller Murphy
    3 Aida Russell
    4 George Smith
    ...
    20 Ashton Wright"
}

If I submit that to the JSON validator at https://jsonlint.com/ I get told it's not valid JSON because of the newlines in the string value for the 'out' attribute.

The problem with your solution is that each \n in your Twig strings is converted to a single newline character so that the output JSON strings contain newline characters as above. You probably need to write \\n instead of \n throughout your Twig code.

Note that if you are using the latest version of CodeRunner and wish to use a Twig preprocessor for the template parameters you need to explicitly select Twig from the dropdown menu. It is no longer the default.

En respuesta a Richard Lobb

Re: SQL Question with Random inputs(bug)

de Daniel Buchberger -
Thank you so much, the change from \n to \\n was the hint! You made my weekend and my day!

I always selected Twig from the dropdown menu!