load_persistent_json()

load_persistent_json()#

The function load_persistent_json() loads a JSON object from a file in a specified directory. It supports exclusive access by keeping the file open if requested.

Prototype

json_t *load_persistent_json(
    hgobj gobj,
    const char *directory,
    const char *filename,
    log_opt_t on_critical_error,
    int *pfd,
    BOOL exclusive,
    BOOL silence
);

Parameters

Key

Type

Description

gobj

hgobj

A handle to the gobj (generic object) that is requesting the JSON load.

directory

const char *

The directory where the JSON file is located.

filename

const char *

The name of the JSON file to be loaded.

on_critical_error

log_opt_t

Logging options to handle critical errors during file operations.

pfd

int *

Pointer to an integer where the file descriptor will be stored if exclusive is TRUE. If exclusive is FALSE, the file is closed after reading.

exclusive

BOOL

If TRUE, the file remains open and its descriptor is stored in pfd. If FALSE, the file is closed after reading.

silence

BOOL

If TRUE, suppresses error logging when the file does not exist.


Return Value

Returns a json_t * representing the loaded JSON object. Returns NULL if the file does not exist or if an error occurs.

Notes

If exclusive is TRUE, the caller is responsible for closing the file descriptor stored in pfd. The function logs errors unless silence is TRUE and on_critical_error is set to LOG_NONE.

Prototype

// Not applicable in JS

Prototype

# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples