Forum Discussion
expression failing when input string contains blanks or null values using this expression “JsonStr.toString().replaceAll(‘\n’,‘’).replaceAll(’ ‘,’')”
any suggestions how to resolve this when we receive blank/null values?
Can you share example of input data(with blank/ null values)
- nchrk3 years agoNew Contributor II
- input value JsonStr := [\n “AC”\n]
expected output := [“AC”] - input value JsonStr := [\n “AC”,\n “BD”,\n “DE” \n]
expected output := [“AC”,“BD”,“DE”] - input value JsonStr := null
expected output := null
- Abhishek_Soni373 years agoContributor
You can use this expression: $JsonStr != null && $JsonStr != “” ? $JsonStr .replaceAll(“\n”,“”) : $JsonStr
Explanation: This will first check if the JsonStr is null or empty, if it’s not then it’ll do the replacing else it’ll just put input jsonStr as output. In your case where JsonStr is null it’ll show output null
- nchrk3 years agoNew Contributor II
Thanks Soni for your response. But i’m getting error when this property is not available in input schema object in mapper.
Error :- $JsonStr is not definedhow do we check the property exists or not. if exists, replace the values
$.get(‘JsonStr) != null && $.get(‘JsonStr) =“” ? $.get(‘JsonStr).toString().replaceAll(’\n’,’'):$.get('JsonStr)
- input value JsonStr := [\n “AC”\n]