You can validate JSON on Input Widget
or Rich Text Editor Widget
, using simple JavaScript. Now say we have an input widget and wanted to print if the JSON is valid or not on a text widget, here’s how we do it.
Say your input widget is named as Input1
, now on the text widget Text
property use the following snippet:
{{
function(){
try { JSON.parse(Input6.text); return "true";
}
catch (e) {
return "false";
}
}()
}}
This function parses through JSON and returns true
if the JSON is valid and false
if the JSON is not valid. Next, update the Input1 valid
property to the following:
{{
Text1.text == "true"
}}
This will add a green border if the JSON is valid.
The following question is also discussed on How Do I Do X on Appsmith Session on our community call. Watch it here: How Do I Do X? - YouTube