|
cwist
Modern C web framework with libttak runtime
|
Multi-stage JSON recovery pipeline with optional schema alignment. More...
#include <cwist/core/utils/json_heal.h>#include <cwist/core/mem/alloc.h>#include <cjson/cJSON.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <ctype.h>
Go to the source code of this file.
Macros | |
| #define | _POSIX_C_SOURCE 200809L |
Functions | |
| int | cwist_json_schema_align (cJSON *obj, const cwist_schema_t *schema, char *log, size_t log_sz) |
| Align a parsed JSON object with a schema in place (L2 stage). | |
| cwist_heal_result_t | cwist_json_heal (const char *input, const cwist_heal_config_t *cfg) |
| Recover malformed JSON using syntax repair, schema alignment, and an optional callback. | |
| void | cwist_heal_result_free (cwist_heal_result_t *r) |
| Free heap storage owned by a healing result. | |
Multi-stage JSON recovery pipeline with optional schema alignment.
Definition in file json_heal.c.
Definition at line 1 of file json_heal.c.
| void cwist_heal_result_free | ( | cwist_heal_result_t * | r | ) |
Free heap storage owned by a healing result.
Free resources owned by a cwist_heal_result_t.
| r | Result object previously populated by cwist_json_heal(). |
Definition at line 584 of file json_heal.c.
References cap, and cwist_heal_result::json.
Referenced by cwist_db_insert_healed().
| cwist_heal_result_t cwist_json_heal | ( | const char * | input, |
| const cwist_heal_config_t * | cfg | ||
| ) |
Recover malformed JSON using syntax repair, schema alignment, and an optional callback.
Attempt to heal a potentially broken JSON string.
The function first attempts a direct parse, then falls back to the internal L1 syntax healer, and finally consults the user-provided SLLM callback when configured. Each successful step records the recovery level, confidence, and a short operator-facing log of the transformations that were applied.
| input | Raw JSON text that may contain structural defects. |
| cfg | Optional recovery configuration. NULL applies the built-in defaults. |
Definition at line 509 of file json_heal.c.
References cap, cwist_heal_result::confidence, cwist_free(), CWIST_HEAL_LOG_MAX, cwist_json_schema_align(), cwist_heal_result::healed, cwist_heal_result::json, cwist_heal_result::level, cwist_heal_result::log, cwist_heal_config::schema, cwist_heal_config::sllm_fn, cwist_heal_config::sllm_userdata, and cwist_heal_config::threshold.
Referenced by cwist_db_insert_healed().
| int cwist_json_schema_align | ( | cJSON * | obj, |
| const cwist_schema_t * | schema, | ||
| char * | log, | ||
| size_t | log_sz | ||
| ) |
Align a parsed JSON object with a schema in place (L2 stage).
Apply L2 schema alignment to an already-parsed cJSON object in place.
For each schema field, locates the corresponding object member by canonical name, explicit alias, or fuzzy match; renames it to the canonical name when found under another key, and coerces its value to the schema's declared type (string/number/bool conversions). All edits and descriptions of each edit are applied directly to obj and log.
| obj | cJSON object to align; must be an object node. |
| schema | Field schema to enforce. |
| log | Optional recovery log (NULL-safe). |
| log_sz | Size of log in bytes. |
Definition at line 358 of file json_heal.c.
References cwist_schema_field::aliases, cap, CWIST_FIELD_ARRAY, CWIST_FIELD_BOOL, CWIST_FIELD_FLOAT, CWIST_FIELD_INT, CWIST_FIELD_OBJECT, CWIST_FIELD_STRING, CWIST_SCHEMA_MAX_ALIASES, cwist_schema::field_count, cwist_schema::fields, cwist_schema_field::name, and cwist_schema_field::type.
Referenced by cwist_json_heal().