llmjson 0.1.0
Initial Release
- Thin wrapper around the Rust crate
llm_json for
repairing malformed JSON strings, particularly those generated by Large
Language Models
Core Features
JSON Repair Functions
repair_json_str() - Repair malformed JSON strings
- Handles missing quotes around keys and values
- Removes trailing commas
- Fixes unquoted keys
- Converts single quotes to double quotes
- Repairs incomplete arrays and objects
- Auto-completes missing values with sensible defaults
repair_json_file() - Read and repair JSON from files
- Direct file reading and repair
- Clear error messages for missing files, permission issues, etc.
repair_json_raw() - Repair JSON from raw byte vectors
- Useful for binary data or reading from connections
- Validates UTF-8 encoding
New: Return R Objects
Directly
- Added
return_objects parameter to all repair functions
- When
TRUE, returns R objects (lists, vectors) instead
of JSON strings
- Works with all three repair functions:
repair_json_str(), repair_json_file(), and
repair_json_raw()
New: Schema Validation System
- Complete schema validation and type conversion system inspired by
the structr
package
- Schema builder functions:
s_map() - Define JSON objects with named fields
s_integer() - Integer fields with optional
defaults
s_double() - Double/numeric fields with optional
defaults
s_string() - String fields with optional defaults
s_logical() - Logical/boolean fields with optional
defaults
s_array() - Arrays with typed elements
s_any() - Accept any JSON type
- Schema features:
- Type coercion (e.g., string “30” to integer 30)
- Optional fields with
.optional = TRUE
- Default values with
.default parameter
- Required field validation
- Nested schemas for complex structures
- Works with both
return_objects = TRUE and
return_objects = FALSE
- Schema benefits:
- Ensures correct R types (integer vs. double vs. string)
- Provides clear error messages for missing required fields
- Handles missing optional fields gracefully
- Validates JSON structure matches expectations