JSON
Powerful JSON serialization and deserialization with automatic class conversion and custom formatting
📋 Table of Contents
💻 JSON in Code
// Create complex data structure
user = {
id: 1,
name: "Alice Johnson",
email: "[email protected]",
active: true,
roles: [ "admin", "developer" ],
metadata: {
lastLogin: now(),
preferences: { theme: "dark", language: "en" }
}
};
// Serialize to JSON
json = user.toJSON();
println( json );
// Pretty print for readability
prettyJson = jsonSerialize( user, pretty: true );
println( prettyJson );
// Deserialize back to BoxLang data
restored = json.fromJSON();
println( "Name: " & restored.name );
// Validate JSON
if ( isJSON( json ) ) {
println( "Valid JSON!" );
}
// List to JSON
tags = "programming,boxlang,json,tutorial";
jsonTags = tags.listToJSON();
println( jsonTags ); // ["programming","boxlang","json","tutorial"]📚 JSON Built-In Functions (BIFs)
Core JSON Functions
Function
Purpose
Member Method Available
Member Method Support
📤 JSON Serialization (jsonSerialize / toJSON)
Basic Serialization
Supported Data Types
🎨 Pretty Printing
🔑 Key Casing Preservation
📊 Query Serialization
🎯 Class Serialization (The Magic!)
Automatic Property Serialization
🔒 Controlling Serialization with Annotations
🎨 Custom toJSON() Method
🔄 Recursive Class Handling
📋 Class Serialization Annotations Reference
📥 JSON Deserialization (jsonDeserialize / fromJSON)
Basic Deserialization
Strict Mapping Mode
Supported JSON Types
Validation Before Deserialization
✅ JSON Validation (isJSON)
📝 List to JSON Conversion
🎯 Advanced JSON Techniques
Working with API Responses
JSON Configuration Files
Nested Data Transformation
JSON Stream Processing
🔧 Custom Serializers (Advanced)
📖 Function Reference
jsonSerialize( data, [queryFormat], [useSecureJSONPrefix], [useCustomSerializer], [pretty] )
jsonDeserialize( json, [strictMapping], [useCustomSerializer] )
isJSON( var )
jsonPrettify( var )
🎓 Best Practices
🔗 Related Documentation
StructuresArraysQueriesClasses & O.O.Last updated
Was this helpful?
