Arrays & JSON
Arrays
Section titled “Arrays”Tulpar supports both mixed-type arrays and type-safe arrays.
// Type-safe arraysarrayInt numbers = [1, 2, 3, 4, 5];arrayStr names = ["Ali", "Veli", "Ayşe"];
// Mixed-type arraysarray mixed = [1, "two", 3.0];
// Array operationsint len = length(numbers);push(numbers, 6);int last = pop(numbers);JSON Objects
Section titled “JSON Objects”Tulpar has first-class support for JSON objects.
// JSON objectsarrayJson user = { "name": "Hamza", "age": 25, "email": "hamza@example.com"};
// Nested objectsarrayJson company = { "name": "Tech Corp", "ceo": { "name": "Hamza", "contact": { "email": "hamza@techcorp.com" } }};Accessing Data
Section titled “Accessing Data”You can access data using bracket notation or dot notation.
// Bracket notationstr name = user["name"];
// Chained accessstr email = company["ceo"]["contact"]["email"];
// Dot notationprint(user.name);company.ceo.contact.email = "new@email.com";JSON Serialization
Section titled “JSON Serialization”Tulpar provides built-in functions for JSON serialization and deserialization.
arrayJson user = { "name": "Ali", "age": 25, "skills": ["C", "Go"] };
// Convert to stringstr js = toJson(user);
// Parse from stringarrayJson back = fromJson(js);