cfml

ColdBox error: Invalid JSON
The document you are trying to decode is not in valid JSON format

Reading time of 268 words
1 minute
Reading time of 268 words ~ 1 minute


Did you find this article helpful?
Please consider tipping me a coffee as a thank you.
Ko-fi Buy Me a Coffee
Did you find this article helpful? Please consider tipping me a coffee or three as a thank you.
Tip using Ko-fi or Buy Me a Coffee

Upon migrating from ColdBox 2.52 over to ColdBox 2.6 I was caught out by a subtle but show stopping issue. Unfortunately the error thrown is not very precise as to the details of the error is or what exactly has triggered it.

invalid json
Invalid JSON

Looking into the pages being called prior to the error you can see the line ..

Called from \coldbox\system\plugins\XMLParser.cfc: line 1013

So one can assume it is probably an issue with one of the XML file, yet which file is not mentioned. However the XML file itself is not the problem, rather it is the data contained within. As JSON or JavaScript Object Notion like XML is another form of human readable data interchange. Unlike XML though JSON is light weight and less complex.

Now if you read the official What’s New Guide for ColdBox 2.6 you can find the following heading ‘JSON notation for dynamic complex settings’.

The configuration file allowed for simple notation to create structures: {name:’luis’,active:’true’} and arrays: [1,2,3]. However, with the inclusion of the new json plugin, you can now declare full JSON syntax notations on ALL complex variables in the configuration file. So you can inflate queries, nested arrays, structures and so much more.

My slipup was that I was transferring an old ColdBox 2.52 coldbox.xml file for use in ColdBox 2.6. I had missed one of my Settings elements under YourSettings that used complex but invalid JSON style data structures. But it was easily fixed with a few single quotes here and there…

2.52 statement

<Setting name="TransferSettings"
value="{datasourceFile:config/datasource.xml.cfm,
transferFile:config/transfer.xml.cfm,
definitions:config/definitions}"/>

2.6 updated statement

<Setting name="TransferSettings"
value="{datasourceFile:'config/datasource.xml.cfm',
transferFile:'config/transfer.xml.cfm',
definitions:'config/definitions'}"/>

Written by Ben Garrett

Did you find this article helpful?
Please consider tipping me a coffee as a thank you.
Ko-fi Buy Me a Coffee
Did you find this article helpful? Please consider tipping me a coffee or three as a thank you.
Tip using Ko-fi or Buy Me a Coffee