'Want to append a Many JsonNodes in 1 Main JsonNode one by one using json-glib Library in C language

JsonNode Structure :-

{
    "order": [
        "ixtrptdktffr9g3oifhgb9r9mo",
    ],
    "posts": {
        "groqkkwhcbgkmg7nt8tsuf8b3e": {
            "id": "groqkkwhcbgkmg7nt8tsuf8b3e",
            "create_at": 1645604110220,
            "update_at": 1645604110220,
            "edit_at": 0,
            "delete_at": 0,
            "is_pinned": false,
            "user_id": "puehqwuo1pnqpdqwax7r4dkgqh",
            "channel_id": "mjqksfjryp8yim7dk1xxic39jw",
            "root_id": "",
            "original_id": "",
            "message": "46",
            "type": "",
            "props": {
                "disable_group_highlight": true
            },
    },
    "next_post_id": "",
    "prev_post_id": "mz9orcyqhpnappszk4satrws1e"
}

So I will have different JsonNodes with same structure coming from API calls one by one and I want to append them one by one into the main JsonNode to create a bigger JsonNode with the same structure and then work on it. Eg:- JsonNodeMain:-Empty initially then JsonNode1:-{"order":[id1],"posts":{some posts}} JsonNodeMain=append(JsonNodeMain,JsonNode1) and similarly in the end I required JsonNodeMain with all the data.

Code:-

mm_got_history_of_room(MattermostAccount *ma, JsonNode *node, gpointer user_data)
{

    static JsonNode *main_node; //this should be the main json node

    JsonObject *obj = json_node_get_object(node);  //this is the json node with data from api call
    JsonObject *posts = json_object_get_object_member(obj, "posts");
    JsonArray *order = json_object_get_array_member(obj, "order");

    main_node=append(main_node,node); //I want something like this
}

This Function is getting called multiple times using recursion and getting different values of JsonNode *node each time.I want to append them in a static jsonNode so that it can retain its value after each recursion call.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source