Templates Example
Template arrays are JSSON’s superpower for handling tabular data. Let’s see them in action!
Basic Template
Section titled “Basic Template”The simplest template array:
users [template { name, age, job, height }João, 19, Student, 1.75Maria, 25, Teacher, 1.65Pedro, 30, Doctor, 1.80Ana, 22, Nurse, 1.68]{"users": [ { "name": "João", "age": 19, "job": "Student", "height": 1.75 }, { "name": "Maria", "age": 25, "job": "Teacher", "height": 1.65 }, { "name": "Pedro", "age": 30, "job": "Doctor", "height": 1.8 }, { "name": "Ana", "age": 22, "job": "Nurse", "height": 1.68 }]}Template with Map Transformation
Section titled “Template with Map Transformation”Add computed fields and transform data:
routes [template { path, method }
map (item) = { path = "/api/v1/" + item.path method = item.method auth = true version = "v1"}
users, GETposts, POSTcomments, DELETEproducts, GET]{"routes": [ { "path": "/api/v1/users", "method": "GET", "auth": true, "version": "v1" }, { "path": "/api/v1/posts", "method": "POST", "auth": true, "version": "v1" }, { "path": "/api/v1/comments", "method": "DELETE", "auth": true, "version": "v1" }, { "path": "/api/v1/products", "method": "GET", "auth": true, "version": "v1" }]}Product Catalog
Section titled “Product Catalog”Real-world e-commerce example:
products [template { id, name, price, category }
map (p) = { id = p.id name = p.name price = p.price category = p.category currency = "USD" inStock = true url = "/products/" + p.id}
1, "Laptop Pro 15", 1299.99, electronics2, "Wireless Mouse", 29.99, accessories3, "USB-C Cable", 12.99, accessories4, "Monitor 27", 399.99, electronics5, "Keyboard Mechanical", 89.99, accessories]{"products": [ { "id": 1, "name": "Laptop Pro 15", "price": 1299.99, "category": "electronics", "currency": "USD", "inStock": true, "url": "/products/1" }, { "id": 2, "name": "Wireless Mouse", "price": 29.99, "category": "accessories", "currency": "USD", "inStock": true, "url": "/products/2" }, { "id": 3, "name": "USB-C Cable", "price": 12.99, "category": "accessories", "currency": "USD", "inStock": true, "url": "/products/3" }, { "id": 4, "name": "Monitor 27", "price": 399.99, "category": "electronics", "currency": "USD", "inStock": true, "url": "/products/4" }, { "id": 5, "name": "Keyboard Mechanical", "price": 89.99, "category": "accessories", "currency": "USD", "inStock": true, "url": "/products/5" }]}Test Data
Section titled “Test Data”Perfect for seeding databases:
testUsers [template { email, password, role, verified }
map (u) = { email = u.email password = u.password role = u.role verified = u.verified createdAt = "2025-11-23T00:00:00Z" active = true}
"admin@test.com", "admin123", admin, true"user1@test.com", "user123", user, true"user2@test.com", "user123", user, false"guest@test.com", "guest123", guest, false]API Endpoints Configuration
Section titled “API Endpoints Configuration”endpoints [template { name, path, method, public }
map (e) = { name = e.name path = "/api" + e.path method = e.method public = e.public rateLimit = 100 timeout = 5000}
getUsers, "/users", GET, falsegetUser, "/users/:id", GET, falsecreateUser, "/users", POST, falsegetPosts, "/posts", GET, truegetPost, "/posts/:id", GET, truecreatePost, "/posts", POST, false]Try It Yourself!
Section titled “Try It Yourself!”- Save any example above to a
.jssonfile - Run:
jsson -i template.jsson -o template.json - See the structured JSON output!
Experiment Ideas
Section titled “Experiment Ideas”Add More Fields
Section titled “Add More Fields”users [template { name, age, email, city, country }João, 25, "joao@test.com", "São Paulo", BrazilMaria, 30, "maria@test.com", Tokyo, Japan]Complex Transformations
Section titled “Complex Transformations”employees [template { firstName, lastName, department }
map (emp) = { fullName = emp.firstName + " " + emp.lastName email = emp.firstName + "@company.com" department = emp.department employeeId = emp.firstName + "-" + emp.department active = true}
João, Silva, EngineeringMaria, Santos, Marketing]Multiple Templates
Section titled “Multiple Templates”users [template { name, email }João, "joao@test.com"Maria, "maria@test.com"]
products [template { name, price }Laptop, 999.99Mouse, 29.99]What’s Next?
Section titled “What’s Next?”- Templates Guide — Complete guide to template arrays
- Demo Example — See basic JSSON features
- Syntax Reference — Full syntax documentation
Templates make JSSON incredibly powerful for structured data! 🚀