I am new to json-c.
I am able to create JSON object in the format:
{"loglevel":"INFO", "msg":"Info about car", "timestamp":"actual system time"}
but I need help in creating the JSON object in the format:
{"module":"log","version":1.0, "logs":[{"loglevel":"INFO", "msg":"Info about car", "timestamp":"actual system time"}]}
Code is below:
/*Line is the messge of string which is passed from other module*/
static void json_file(char *line)
{
FILE* lg;
lg = fopen(JSON_FILE,"ab+");
char *json = "{\"key1\":\"data\", \"key2\":1.0, \"Logs\":[";
fwrite(line, sizeof(char), strlen(line),lg);
fputs("]}", lg);
/*replace last ']}' with ',' json string and ]} */
char stringtofind[4] = "]}";
char get_line[2000];
fgets(get_line, sizeof(get_line), lg);
if (strstr(get_line, stringtofind) != NULL)
{
printf("substring found \n");
/* Help Required here*/
/* please help */
// Need to replace the "]}" into ","
}
}