Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Coldfusion 9 serializeJSON()

Anytime that I use serializeJSON in cf9 the JSON it returns is prepended with '//'. This is pretty frustrating because even coldfusion will throw an error trying to decode that as json. For example:

var a = { stuff = 'some content' };
a = serializejSON( a ); // the content of a is now: //{"STUFF":"some content"}
b = deserializeJSON( a );

The above code will throw an error saying something like 'unable to parse character at position 1: /'. In order to make this work I have to do a string replace and swap out '' for the '//'.

I can't seem to find any information on this issue. Is this some sort of feature that I don't understand and is working as intended? Am I missing some sort of setting that fixes this?

like image 605
etchesketch Avatar asked Jun 10 '15 14:06

etchesketch


People also ask

What is SerializeJSON?

The SerializeJSON function converts all other ColdFusion data types to the corresponding JSON types. It converts structures to JSON Objects, arrays to JSON Arrays, numbers to JSON Numbers, and strings to JSON Strings.

How do I deserialize JSON in ColdFusion?

A Boolean value that specifies whether to convert the JSON strictly, as follows: true: (Default) Convert the JSON string to ColdFusion data types that correspond directly to the JSON data types. false: Determine if the JSON string contains representations of ColdFusion queries, and if so, convert them to queries.

How do I deserialize JSON?

A common way to deserialize JSON is to first create a class with properties and fields that represent one or more of the JSON properties. Then, to deserialize from a string or a file, call the JsonSerializer. Deserialize method.

What is serializing and deserializing JSON?

JSON is a format that encodes objects in a string. Serialization means to convert an object into that string, and deserialization is its inverse operation (convert string -> object).


1 Answers

You can disable this in the ColdFusion administrator. Go to Server Settings > Settings and uncheck Prefix serialized JSON with

There are, however, security implications if you turn this off. This helps protect your JSON data from cross-site scripting attacks and is explained more in depth in this StackOverflow answer

like image 68
Matt Busche Avatar answered Sep 18 '22 04:09

Matt Busche