How To The Write `isJSON( )` Function In ColdFusion?
Description:-
Determines whether a string is in valid JSON (JavaScript Object Notation) data interchange format or not.
isJSON( value );
This function return type is a boolean value, true
or false
.
Attributes:-
value:-
This is a required argument, an object or variable that needs to be checked.
Example:-
<cfscript>
test = {
"a" : 100,
"b" : 200
};
writeDump( "Before JSON Convert: #isJSON( test )#" );
writeDump( "Before JSON Convert: #isJSON( test.toJSON( ) )#" );
</cfscript>
Result:-
Before JSON Convert: NO
Before JSON Convert: YES
In this example first, we check this test structures variable then convert this structure to JSON and again check if it is a JSON format or not.