Evaluates whether a string is in valid JSON (JavaScript Object Notation) data interchange format.
True if the parameter is a valid JSON value.
False if the parameter is not a valid JSON data representation.
IsJSON(var)
DeserializeJSON, SerializeJSON, cfajaxproxy, "Using Ajax Data and Development Features" in the ColdFusion Developer's Guide, http://www.json.org
ColdFusion 8: Added function
Parameter |
Description |
---|---|
var |
A string or variable that represents one. |
This example checks whether the data feed that is generated by the example for the SerializeJSON function contains valid JSON data.
The feed is in the form of a JavaScript function call where the parameter is a JSON string that contains the feed data. The example does the following operations:
To run this example, put this file and the example for the SerializeJSON function in an appropriate location under your ColdFusion web root, replace the URL with the correct URL for the serialization example, and run this page.
<!--- Get the JSON Feed ---> <cfhttp url="http://localhost:8500/My_Stuff/Ajax/Books/CreateJSON_NEW.cfm"> <!--- JSON data is often distributed as a JavaScript function. The following REReplace functions strip the function wrapper. ---> <cfset theData=REReplace(cfhttp.FileContent, "^\s*[[:word:]]*\s*\(\s*","")> <cfset theData=REReplace(theData, "\s*\)\s*$", "")> <!--- Test to make sure you have JSON data. ---> <cfif isJSON(theData)> <h3>The URL you requested provides valid JSON</h3> <cfelse> <h3>The URL you requested does not provide valid JSON</h3> </cfif> <!--- Display the data. ---> <cfoutput>#theData#</cfoutput>
For a more complex example that then converts the JSON data, see DeserializeJSON.