I'm working on a project using a Renesas MCU with the NetX module, where I'm utilizing the cJSON library to parse JSON data from a file. On my PC, the parsing works perfectly fine regardless of the size of the JSON file. However, when I deploy the same code to the Renesas MCU, cJSON_Parse() starts throwing parse errors for JSON files with more than 50 lines.
Here's a simplified version of my code:
#include <stdio.h>
#include <stdlib.h>
#include "cJSON.h"
int main() {
FILE *fp;
char buffer[10240];
cJSON *json;
strcpy(buffer, "valid json string");
json = cJSON_Parse(buffer); // if buffer too long, it can not parse correctly.
if (json == NULL) {
const char *error_ptr = cJSON_GetErrorPtr();
if (error_ptr != NULL) {
printf("Error before: %s\n", error_ptr);
}
cJSON_Delete(json);
return 1;
}
// Process JSON data here...
cJSON_Delete(json);
return 0;
}
Despite working fine on my PC, cJSON_Parse() starts failing when the JSON string exceeds(if in a file, around 50 lines) on the Renesas MCU with the NetX module. Are there any specific limitations or considerations I should be aware of when using cJSON library on this platform? How can I ensure proper parsing for larger JSON files on this MCU?
PS: suggestions are MCU stack size limitation, but how to configure it?
Any insights or suggestions would be greatly appreciated. Thanks in advance!
MCUs typically have much more limited RAM and storage compared to a PC. The buffer size of 1024 bytes may not be sufficient to hold larger JSON files in their entirety, leading to incomplete data being passed to cJSON_Parse(), which could cause parsing errors.
Try out this: