/** * @file json_helpers.h * @brief Declares the public json helpers API. */ #ifndef _JSON_HELPERS_H_ #define _JSON_HELPERS_H_ #include #include "staticstring.h" /** * @brief Get json object value. * @param obj Object to initialize, inspect, or modify. * @param key JSON object key or property name to locate. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_object_value(json_t *obj, char *key, json_t **dest); /** * @brief Get json boolean value. * @param obj Object to initialize, inspect, or modify. * @param key JSON object key or property name to locate. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_boolean_value(json_t *obj, char *key, bool *dest); /** * @brief Get json integer value. * @param obj Object to initialize, inspect, or modify. * @param key JSON object key or property name to locate. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_integer_value(json_t *obj, char *key, int *dest); /** * @brief Get json number value. * @param obj Object to initialize, inspect, or modify. * @param key JSON object key or property name to locate. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_number_value(json_t *obj, char *key, float *dest); /** * @brief Get json double value. * @param obj Object to initialize, inspect, or modify. * @param key JSON object key or property name to locate. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_double_value(json_t *obj, char *key, double *dest); /** * @brief Get json string value. * @param obj Object to initialize, inspect, or modify. * @param key JSON object key or property name to locate. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_string_value(json_t *obj, char *key, akgl_String **dest); /** * @brief Get json array value. * @param obj Object to initialize, inspect, or modify. * @param key JSON object key or property name to locate. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_value(json_t *obj, char *key, json_t **dest); /** * @brief Get json array index object. * @param array JSON array to read. * @param index Zero-based element index. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_OUTOFBOUNDS When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_index_object(json_t *array, int index, json_t **dest); /** * @brief Get json array index integer. * @param array JSON array to read. * @param index Zero-based element index. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_OUTOFBOUNDS When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_index_integer(json_t *array, int index, int *dest); /** * @brief Get json array index string. * @param array JSON array to read. * @param index Zero-based element index. * @param dest Output destination populated by the function. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. * @throws AKERR_OUTOFBOUNDS When the corresponding validation or operation fails. * @throws AKERR_TYPE When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_array_index_string(json_t *array, int index, akgl_String **dest); /** * @brief Get json with default. * @param e Error context to inspect and optionally consume. * @param defval Fallback value copied when the supplied error is eligible. * @param dest Output destination populated by the function. * @param defsize Size in bytes of the fallback value. * @return `NULL` on success, otherwise an error context owned by the caller. * @throws AKERR_INDEX When the corresponding validation or operation fails. * @throws AKERR_KEY When the corresponding validation or operation fails. * @throws AKERR_NULLPOINTER When the corresponding validation or operation fails. */ akerr_ErrorContext AKERR_NOIGNORE *akgl_get_json_with_default(akerr_ErrorContext *e, void *defval, void *dest, uint32_t defsize); #endif // _JSON_HELPERS_H_