Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
August 20, 2021 06:19 pm GMT

isJsonStructure() CFML User-Defined Function

Apparently strings, numbers, true, false and null are considered valid JSON even though they consist of a single escaped value. (I recently discovered this while accepting API data from a third-party and they accidentally double-encoded the JSON body payload.

To prevent this issue from occurring again, I wrote a CFML User-Defined Function (UDF) to test whether a string can successfully parsed to an object and/or array (versus accepting an invalid simple value). Enjoy!

isJsonStructure(string, type="any")

https://gist.github.com/JamoCA/e153c2ea40bfd75b60d180fbb709fe5b

function comparisons between isJson and isJsonStructure


Original Link: https://dev.to/gamesover/isjsonstructure-cfml-user-defined-function-1kg9

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To