JSON
The JSON module provides comprehensive JSON (JavaScript Object Notation) capabilities for Soul, including parsing, serialization, and validation. It offers both Soul-style and JavaScript-style aliases for familiar API usage.Parsing JSON
decode / parse - Parse JSON string to object
Parse a JSON string into Soul objects (maps or lists):Parsing Complex Structures
Parse nested JSON structures:Serialization
encode / stringify - Convert object to JSON string
Convert Soul objects (maps or lists) to JSON strings:Serializing Complex Objects
Serialize nested structures:Validation
isValid - Check if string is valid JSON
Validate whether a string contains valid JSON:Data Type Handling
Supported Data Types
The JSON module handles all standard JSON data types:Map Key Conversion
When encoding maps, different key types are converted to strings:Error Handling
Parsing Errors
Handle JSON parsing errors gracefully:Encoding Errors
Handle encoding errors for unsupported types:Practical Examples
Configuration File Handling
API Response Handling
Data Transformation Pipeline
Working with JSON Arrays
JSON Validation Workflow
Best Practices
- Always validate before parsing: Use
isValid()to check JSON validity before parsing - Handle errors gracefully: Check for ERROR types when parsing or encoding
- Use appropriate aliases: Choose
decode/encodeorparse/stringifybased on your preference - Be aware of type limitations: Only LIST and MAP types can be encoded to JSON
- Consider memory usage: Large JSON strings can consume significant memory

