I am writing a generic function to generate JSON string from a structure which takes a structure as input and returns a JSON formatted string.
Example:
#define LF "\n"
struct object {
int number;
char *name;
char status;
};
char *json_stringify(void *s, char *type)
{
char *result;
....
....
return result;
}
int main()
{
struct object obj ={
.number = 1000,
.name = "ajith",
.status = 'S'
};
printf("Result : %s"LF, json_stringify(&obj,"struct object"));
return 0;
}
I need to write the json_stringify() function which produce an output like follows,
{"number":1000,"name":"ajith","status":"S"}
But is it possible to identify the member variable names of a structure at runtime?
Where is the structure definition details are kept by the compiler?
Note: I am using a CentOS-6 Linux distribution with gcc.
Please help me... Thanks in advance.