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 p…


This content originally appeared on DEV Community and was authored by James Moberg

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


This content originally appeared on DEV Community and was authored by James Moberg


Print Share Comment Cite Upload Translate Updates
APA

James Moberg | Sciencx (2021-08-20T18:19:11+00:00) isJsonStructure() CFML User-Defined Function. Retrieved from https://www.scien.cx/2021/08/20/isjsonstructure-cfml-user-defined-function/

MLA
" » isJsonStructure() CFML User-Defined Function." James Moberg | Sciencx - Friday August 20, 2021, https://www.scien.cx/2021/08/20/isjsonstructure-cfml-user-defined-function/
HARVARD
James Moberg | Sciencx Friday August 20, 2021 » isJsonStructure() CFML User-Defined Function., viewed ,<https://www.scien.cx/2021/08/20/isjsonstructure-cfml-user-defined-function/>
VANCOUVER
James Moberg | Sciencx - » isJsonStructure() CFML User-Defined Function. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/20/isjsonstructure-cfml-user-defined-function/
CHICAGO
" » isJsonStructure() CFML User-Defined Function." James Moberg | Sciencx - Accessed . https://www.scien.cx/2021/08/20/isjsonstructure-cfml-user-defined-function/
IEEE
" » isJsonStructure() CFML User-Defined Function." James Moberg | Sciencx [Online]. Available: https://www.scien.cx/2021/08/20/isjsonstructure-cfml-user-defined-function/. [Accessed: ]
rf:citation
» isJsonStructure() CFML User-Defined Function | James Moberg | Sciencx | https://www.scien.cx/2021/08/20/isjsonstructure-cfml-user-defined-function/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.