You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add data serialization functions and enhance read_lines
## New Features
### Data Serialization Functions
- Add `to_json(object, pretty)` - Convert objects to JSON strings
- Optional pretty-printing with indentation
- Supports all data types (objects, arrays, primitives)
- Add `to_yaml(object)` - Convert objects to YAML strings
- Clean, human-readable output
- Supports nested structures and arrays
- Add `to_toml(object)` - Convert objects to TOML strings
- Supports tables, nested tables, and array of tables
- Ideal for configuration files
### Enhanced read_lines Function
- Extend `read_lines(path, max_lines)` with flexible line selection:
- Positive number: Read first N lines (existing behavior)
- Negative number: Read last N lines (new)
- Zero: Read entire file (new)
- Useful for log file analysis and tail-like operations
## Implementation Details
- Create src/functions/serialization.rs with all 3 functions
- Modify read_lines to support negative/zero max_lines values
- Register functions in mod.rs
- Add 29 comprehensive serialization tests
- Add 3 new read_lines tests for edge cases
- Total: 505 passing tests
## Documentation
- Add "Data Serialization Functions" section to README.md
- Complete examples for each function
- Practical use cases (Kubernetes configs, Cargo.toml, format conversion)
- Update read_lines documentation with all modes
- Update TODO.md to mark serialization as complete
- Add to features list and table of contents
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Convert objects and data structures to formatted strings (JSON, YAML, TOML). Useful for generating configuration files, API payloads, or converting between formats.
1837
+
1838
+
#### `to_json(object, pretty)`
1839
+
1840
+
Convert an object to a JSON string.
1841
+
1842
+
**Arguments:**
1843
+
- `object` (required) - Object/value to convert to JSON
1844
+
- `pretty` (optional) - Enable pretty-printing with indentation (default: false)
0 commit comments