1#ifndef __CWIST_JSON_HEAL_H__
2#define __CWIST_JSON_HEAL_H__
33#include <cjson/cJSON.h>
49#define CWIST_SCHEMA_MAX_ALIASES 8
89typedef char *(*cwist_sllm_heal_fn)(
const char *broken_json,
const cwist_schema_t *schema,
108#define CWIST_HEAL_LOG_MAX 512
int cwist_json_schema_align(cJSON *obj, const cwist_schema_t *schema, char *log, size_t log_sz)
Apply L2 schema alignment to an already-parsed cJSON object in place.
struct cwist_heal_config cwist_heal_config_t
Configuration passed to cwist_json_heal().
struct cwist_schema cwist_schema_t
A complete schema: array of field descriptors + count.
cwist_field_type_t
Expected value type for a schema field.
#define CWIST_HEAL_LOG_MAX
struct cwist_schema_field cwist_schema_field_t
Single field descriptor used by both the healer and the Zod validator.
#define CWIST_SCHEMA_MAX_ALIASES
struct cwist_heal_result cwist_heal_result_t
Result of a healing attempt.
void cwist_heal_result_free(cwist_heal_result_t *r)
Free resources owned by a cwist_heal_result_t.
char *(* cwist_sllm_heal_fn)(const char *broken_json, const cwist_schema_t *schema, void *userdata)
Optional deep-recovery callback (e.g. backed by an LLM).
cwist_heal_result_t cwist_json_heal(const char *input, const cwist_heal_config_t *cfg)
Attempt to heal a potentially broken JSON string.
Configuration passed to cwist_json_heal().
void * sllm_userdata
Passed verbatim to sllm_fn.
const cwist_schema_t * schema
Schema for L2 alignment (may be NULL).
double threshold
Min confidence (0.0–1.0) to accept recovery. Default: 0.8.
cwist_sllm_heal_fn sllm_fn
Optional L3 deep-recovery callback.
Result of a healing attempt.
char * json
Healed JSON string (free with cwist_heal_result_free). NULL on failure.
bool healed
True if any modification was made.
double confidence
Estimated confidence in the recovery (0.0–1.0).
int level
Recovery level reached: 0=none, 1=L1, 2=L2, 3=L3.
char log[CWIST_HEAL_LOG_MAX]
Human-readable description of changes made.
Single field descriptor used by both the healer and the Zod validator.
bool required
Must be present?
const char * name
Canonical field name.
const char * aliases[CWIST_SCHEMA_MAX_ALIASES]
Alternative names (NULL-terminated).
cwist_field_type_t type
Expected value type.
A complete schema: array of field descriptors + count.
const cwist_schema_field_t * fields