load_json_from_file()
#
The function load_json_from_file()
loads a JSON object from a file located in the specified directory. It returns a parsed JSON object if successful, or NULL if the file does not exist or an error occurs.
Prototype
json_t *load_json_from_file(
hgobj gobj,
const char *directory,
const char *filename,
log_opt_t on_critical_error
);
Parameters
Key |
Type |
Description |
---|---|---|
|
|
A handle to a GObj, used for logging errors. |
|
|
The directory where the JSON file is located. |
|
|
The name of the JSON file to be loaded. |
|
|
Logging options to handle critical errors. |
Return Value
Returns a json_t *
object containing the parsed JSON data if successful, or NULL if the file does not exist or an error occurs.
Notes
The function uses json_loadfd()
to parse the JSON file. If the file does not exist, it returns NULL without logging an error. If an error occurs while opening or parsing the file, it logs an error message using gobj_log_critical()
.
Prototype
// Not applicable in JS
Prototype
# Not applicable in Python
Examples
// TODO C examples
// TODO JS examples
# TODO Python examples