<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>cJSON Parse failure / Failed to print JSON object</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/119399/cjson-parse-failure-failed-to-print-json-object</link><description>Hi everyone, 
 I am using SDK Toolchain v2.3.0 and my code is based on the aws_iot example. I am getting either &amp;quot;cJSON Parse failure&amp;quot; or &amp;quot;Failed to print JSON object&amp;quot; error if I leave the device running for days. The device will be stuck with that error</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 03 Mar 2025 11:39:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/119399/cjson-parse-failure-failed-to-print-json-object" /><item><title>RE: cJSON Parse failure / Failed to print JSON object</title><link>https://devzone.nordicsemi.com/thread/525485?ContentTypeID=1</link><pubDate>Mon, 03 Mar 2025 11:39:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b497700b-42a7-4d53-bd56-d48bcc1bafcd</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user="flau"]Increasing the heap and stack sizes seems to correct the problem.[/quote]
&lt;p&gt;It may be difficult to know if this just delays the problem, or if it makes it less likely to occur, or if it fixes it entirely. Nevertheless, if you do have more memory left, increasing stack and/or heap further could help also for the current issue.&lt;/p&gt;
[quote user="flau"]reset whenever I see &amp;quot;cJSON Parse failure&amp;quot; or &amp;quot;Failed to print JSON object&amp;quot;.[/quote]
&lt;p&gt;This is of course also a valid workaround, if it doesn&amp;#39;t happen too often.&lt;/p&gt;
&lt;p&gt;I guess if you could also monitor memory usage, then you would see if you somehow got a data buildup or stack buildup.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON Parse failure / Failed to print JSON object</title><link>https://devzone.nordicsemi.com/thread/525323?ContentTypeID=1</link><pubDate>Fri, 28 Feb 2025 15:10:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0332c2d7-4451-4ac3-94db-f2ffbd17196a</guid><dc:creator>flau</dc:creator><description>&lt;p&gt;Thank you very much for all the inputs.&amp;nbsp; The occurrence is very difficult to catch.&amp;nbsp; I have 7 devices running at the same time, 3 with 1NCE SIM and 4 with Truphone SIM.&amp;nbsp; So far no cJSON error happened to the 4 with Truphone SIM.&amp;nbsp; For the other 3, 1 had the error after 4 days, 1 had the error after 7 days, 1 had the error after 8 days.&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I remember having the cJSON error early in the project with iBASIS SIM.&amp;nbsp; Increasing the heap and stack sizes seems to correct the problem.&amp;nbsp; Here is what I have right now.&lt;/p&gt;
&lt;p&gt;# Heap and stacks&lt;br /&gt;CONFIG_MAIN_STACK_SIZE=8192&lt;br /&gt;CONFIG_HEAP_MEM_POOL_SIZE=49152&lt;br /&gt;CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=8192&lt;br /&gt;CONFIG_AT_MONITOR_HEAP_SIZE=2048&lt;/p&gt;
&lt;p&gt;The cJSON_Delete(root_obj) function doesn&amp;#39;t seem to fix the problem.&amp;nbsp; Yesterday, I put a watchdog reset whenever I see &amp;quot;cJSON Parse failure&amp;quot; or &amp;quot;Failed to print JSON object&amp;quot;.&amp;nbsp; I will let the devices run for another week or so to see what will happen.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Floyd&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON Parse failure / Failed to print JSON object</title><link>https://devzone.nordicsemi.com/thread/525312?ContentTypeID=1</link><pubDate>Fri, 28 Feb 2025 14:41:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b6ccd2d7-dcf9-4a19-a3ff-87d495d8a955</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
[quote user=""]According to 1NCE, they saw a PDP context is opened for days.&amp;nbsp; Is this the reason for the cJSON error?[/quote]
&lt;p&gt;It cannot be ruled out that it is somehow related. E.g., does it lead to larger JSON objects? Does it lead to stack overflow or otherwise memory exhaustion?&lt;/p&gt;
[quote user=""]device will be stuck with that error and never recover unless I reboot.[/quote]
&lt;p&gt;This might have to do with the application logic. E.g., are you retrying indefinitely to handle the same (faulty) JSON structure? This could be multiple different types of infinite loop, deadlock (or even livelock), or other. Since it happens after a few days, a debug session for investigating the state of the device when this happens might be difficult, but increased logging would be a good plan B.&lt;/p&gt;
[quote user="Jakob Ruhe"]The best would be to log the data that cJSON fails to parse or print. Probably the data is corrupt in some way. But it is hard to guess without seeing the data.[/quote]
&lt;p&gt;Having the data definitely could shed some light on what might be the issue. In addition, exact API calls and (error) return values, what is the state of the device when failing, etc. any additional information, really.&lt;/p&gt;
&lt;p&gt;If the root cause is not found, there could still be possible workarounds, e.g. closing the PDP context, or using a watchdog to reset the device, etc.&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: cJSON Parse failure / Failed to print JSON object</title><link>https://devzone.nordicsemi.com/thread/525237?ContentTypeID=1</link><pubDate>Fri, 28 Feb 2025 10:12:12 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:07efa56d-892f-4235-823a-9d0841c4547f</guid><dc:creator>Jakob Ruhe</dc:creator><description>&lt;p&gt;The best would be to log the data that cJSON fails to parse or print. Probably the data is corrupt in some way. But it is hard to guess without seeing the data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>