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 Developing ColdFusion Applications, 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:
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