Skip to content

LouisLanganay/json-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

json_parser lib

A json parser for RPG project

Exe compilation

To compile this project run the following command at lib/jp

    make

Usefull functions

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);

Example

SEARCHER

{
    "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;

WRITER

{
    "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);

parsed_data_t struct

JSON PARSER

How Json Work ?

1j 2j 3j 4j 5j 6j

Authors

Logo