How to write test case for JSON value?

Certified Associate Developer

Hi everyone, sorry in advance for a confusing question. So I have this expression rule with two rule inputs, ri!innitiator and ri!excelSheetJSON, the code works well but I have to create the test cases for each of the rule inputs and I have no Idea how I'm supposed to structure the excelSheetJSON one. I provided the code used in the expression rule, in the PM node where we included the JSON code and the test case page where you can establish the parameter for the case. My question is what do I write in the red box to give the appropriate output? 

 (In the expression rule)

 (In the PM)

 (In the expression rule)

Thanks for the help!!

  Discussion posts and replies are publicly visible

  • Just... paste an example of the JSON-conversion that happens when that rule is fed the excel sheet, perhaps?  I'm not really clear what you're after, overall.  There's no law saying every single expression rule has to have test inputs, BTW (though it certainly does speed up testing future changes to the rule if ever needed).

  • 0
    Certified Senior Developer

    Hi Nickk,

    If my understanding is correct, you are trying to provide the JSON value as text input to an ri! and then consume the value in the expression rule by changing it to a proper JSON format. Try following the below steps.

    1. Copy the test JSON input which needs to be added in the test case.
    2. Replace all the double quotes in the text with two double quotes. Eg: {"name": "Ron"}   ->  {""name"": ""Ron""}
    3. Enclose the entire test input in double quote. Eg: {""name"": ""Ron""}  ->  "{""name"": ""Ron""}"
    4. Paste the text in the expression part of the rule input.
    5. Use a!fromjson() to convert the ri!'s data to JSON format.