A json parser for RPG project
To compile this project run the following command at lib/jp
make
parsed_data_t *jp_parse(char *filepath);
parsed_data_t *jp_search(parsed_data_t *data, char *name);
void jp_write(char *filepath, parsed_data_t *object);
{
"name": "Louis",
"hp": 100,
"alive": true,
"pos": {
"x": 11110, // -- HERE --
"y": 220
},
"inventory": {
"size": 12,
"bag": true,
"items": [
1,
2,
40
]
}
}
If I want to acces to player pos_x:
parsed_data_t *data = jp_parse(JSON_FILE_PATH);
int pos_x = jp_search(data, "pos.x")->value.p_int;
{
"michel": {
"dialogues": [
{
"id": 1,
"posibilities": [
"Hello!",
"Bonjour aventurier !", // -- HERE --
"Salut à toi !"
]
},
{
"id": 2,
"posibilities": [
"Merci"
]
}
]
}
}
If I want to modify second posibility
of the first dialogue
of michel
:
parsed_data_t *data = jp_parse(JSON_FILE_PATH);
jp_search(data, "michel.dialogues[0].posibilities[0]")->value.p_str = "Bonjour grand aventurier !";
jp_write(JSON_FILE_PATH, data);