LLML Rust
Rust implementation of the Lightweight Markup Language (LLML) - a library that converts JSON data structures into XML-like markup with intelligent formatting.
Features
- Simple Key-Value Conversion:
{"key": "value"}→<key>value</key> - Array Formatting: Arrays become numbered lists with wrapper tags
- Nested Object Support: Recursive processing with kebab-case key conversion
- Configurable Indentation: Customizable spacing and prefixes
- Multiline String Handling: Proper formatting for multiline content
- Kebab-Case Conversion: Automatic conversion of camelCase and snake_case keys
- Strict Mode Control: Choose whether nested properties include parent key prefixes
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use llml;
use json;
Advanced Usage
Custom Formatting Options
use ;
use json;
let data = json!;
let options = Some;
let result = llml;
// Output: <app-message>Hello World</app-message>
// Example with strict mode
let data = json!;
let options = Some;
let result = llml;
// Output: <config>
// <config-debug>true</config-debug>
// <config-timeout>30</config-timeout>
// </config>
// Example with strict mode disabled (default)
let options = Some;
let result = llml;
// Output: <config>
// <debug>true</debug>
// <timeout>30</timeout>
// </config>
Handling Complex Data Structures
let complex_data = json!;
let result = llml;
// Produces nested XML-like structure with kebab-case keys
Key Transformations
| Input | Output |
|---|---|
user_name |
user-name |
maxRetries |
max-retries |
key with spaces |
key-with-spaces |
Supported Data Types
- Primitives: Strings, numbers, booleans, null
- Arrays: Converted to numbered lists with wrapper tags
- Objects: Recursively processed with nested tag structure
- Empty Values: Handled gracefully (empty objects/arrays → empty strings)
Examples
Run the included examples to see LLML in action:
This will demonstrate:
- Simple key-value formatting
- Array handling
- Nested objects
- Mixed content
- Custom indentation
- Empty value handling
Testing
Run the comprehensive test suite:
The library includes extensive tests covering:
- Edge cases (empty values, null, zero, false)
- Data type conversions
- Kebab-case transformations
- Nested structures
- Indentation and prefixes
- Multiline content
Architecture
The library uses a recursive formatter that:
- Processes JSON values based on their type
- Converts keys to kebab-case format
- Handles arrays as numbered lists with wrapper tags
- Maintains proper indentation for nested structures
- Preserves multiline string formatting
Contributing
This is part of the LLML project. See the main repository for contribution guidelines.
License
MIT