Description
Evaluates whether a string is in valid JSON (JavaScript Object Notation) data interchange format.
Returns
True if the parameter is a valid JSON value.False if the parameter is not a valid JSON data representation.
Category
Syntax
IsJSON(var)
See also
DeserializeJSON, SerializeJSON, cfajaxproxy, Using Ajax Data and Development Features in the Developing ColdFusion Applications, http://www.json.org
History
ColdFusion 8: Added function
Parameters
Parameter |
Description |
---|---|
var |
A string or variable that represents one. |
Example
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:
- Uses a cfhttp tag to get the feed (in the cfhttp.fileContent variable).
- Strips the function call wrapper from the text.
- Uses the IsJSON function to check whether the result of the previous step is a valid JSON format string.
Displays a message that indicates whether the text is valid JSON data, followed by the feed text string.To run this example, put this file and the example for the SerializeJSONfunction in an appropriate location under your ColdFusion web root, replace the URL with the correct URL for the serialization example, and run this page.
<cfscript> myObj= {name: "John", age: 31, city: "New York"}; myJSON = IsJSON(myObj); writeoutput(myJSON); </cfscript>
Output
NO
For a more complex example that then converts the JSON data, see DeserializeJSON.
Sign in to your account