I have a Json file named name.json An example of such a Json file can be seen bellow
{
"set": 5,
"low": 0,
"draw_set": "0.1 up to 0.3",
"Wupet": "Hold",
"": null
}
But it can be also the case that another time the Json file has another structure.
{
"set": 5,
"low": 0,
"draw_set": "0.1 up to 0.3",
"W_set": "Ramp 1.5 ∞C/min",
"Wset": 0,
"Wupet": "Hold",
"": null
}
I want to convert the input of this Json file (the attributes and their types can be different in each file) to a C struct where the structs automatically detects which attributes (and their types) there are in the Json file. The attribute "" in "": null (can be given a random attribute name)
Then I want to automatically assign the values of Json value to the struct of object Book1.
Plan of my code
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Books {
float set[50];
int low[50];
char draw_set[100];
char Wupet[100];
};
int main( ) {
/* Read name.Json file */
struct Books Book1; /* Declare Book1 of type Book */
/* Convert content Json to Struct Book1 with it's actual values*/
return 0;
}
Edit: I don't want to ignore "Wset" and "W_set" keys if they exist in the Json file. The keys of the Json files are changing everything time (there are many unknown attributes that can occur in the future). The number of keys is not guarantee. The 'split over multiple lines' property is guaranteed? The null key name should be given a random name (multiple keys can occurs with like the null key name) The attribute types of the struct should be automatically detected and created. The Json file contains a single record (object)
I want to deal with these structures at runtime.