Patrick
12/20/2023, 2:31 AMserializeJSON() is super helpful to out my data for use. But my problem is that serializeJSON wraps the name and every value-set with double quotes. Is it possible to modify this or some examples for modifying the outcome of serializeJSON? I havent found much about implementing the *useCustomSerializer* arg.Patrick
12/20/2023, 2:35 AMcoordinates value to not be a string but rather just [-75.9999,36.9999] but it serializes as "[-75.9999,36.9999]"Cage S
12/20/2023, 3:28 AM<cfscript>
var myStruct = {
'coordinates': [-75.9999,36.9999]
};
dump(serializeJson(myStruct));
</cfscript>Patrick
12/20/2023, 3:29 AMCONCAT('[', al.lng, ',', al.lat, ']') as COORDS which makes it a stringCage S
12/20/2023, 3:29 AMgavinbaumanis
12/20/2023, 3:30 AM.toJSON()
<https://docs.lucee.org/reference/objects/any/tojson.html>
The example code - would seem to show it gives you the format you're after.Cage S
12/20/2023, 3:32 AM.toJSON() is the same as serializeJson()?gavinbaumanis
12/20/2023, 3:32 AMst.data = "[1,2,3,4,5]";
Only produces a single set of quotes - not a doubled-up version.gavinbaumanis
12/20/2023, 3:36 AMwriteDump(serializeJson(st.data));
On tryCF - also produces a single quote version...
But I also see in my own use of serializeJSON - that I use for logging / dumping :- "double-double" quotes, too.
Weird indeed!Cage S
12/20/2023, 3:40 AMserializeJSON , replace the double quotes with nothing, and then return the resultant string? Or does your database support native JSON conversion (though I imagine if it does, it does it to the JSON standard)?Patrick
12/20/2023, 3:42 AMJSON.parse(mycolumnvalue)Patrick
12/20/2023, 3:43 AMPatrick
12/20/2023, 3:46 AMCage S
12/20/2023, 4:32 AMdeserializeJSON() . I assumed you had already parsed the JSON string in Javascript before handing off to your library & you were still getting the double quoting after deserialization.
BTW, check out: https://www.w3schools.com/js/js_json_parse.asp and the reviver parameter. Looks interesting - I didn't know this parameter existed for JSON.parse.
const text = '{"name":"John", "birth":"1986-12-14", "city":"New York"}';
const obj = JSON.parse(text, function (key, value) {
if (key == "birth") {
return new Date(value);
} else {
return value;
}
});