Skip to content

Templates Example

Template arrays are JSSON’s superpower for handling tabular data. Let’s see them in action!

The simplest template array:

users [
template { name, age, job, height }
João, 19, Student, 1.75
Maria, 25, Teacher, 1.65
Pedro, 30, Doctor, 1.80
Ana, 22, Nurse, 1.68
]

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, GET
posts, POST
comments, DELETE
products, GET
]

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, electronics
2, "Wireless Mouse", 29.99, accessories
3, "USB-C Cable", 12.99, accessories
4, "Monitor 27", 399.99, electronics
5, "Keyboard Mechanical", 89.99, accessories
]

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
]
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, false
getUser, "/users/:id", GET, false
createUser, "/users", POST, false
getPosts, "/posts", GET, true
getPost, "/posts/:id", GET, true
createPost, "/posts", POST, false
]
  1. Save any example above to a .jsson file
  2. Run: jsson -i template.jsson -o template.json
  3. See the structured JSON output!
users [
template { name, age, email, city, country }
João, 25, "joao@test.com", "São Paulo", Brazil
Maria, 30, "maria@test.com", Tokyo, Japan
]
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, Engineering
Maria, Santos, Marketing
]
users [
template { name, email }
João, "joao@test.com"
Maria, "maria@test.com"
]
products [
template { name, price }
Laptop, 999.99
Mouse, 29.99
]

Templates make JSSON incredibly powerful for structured data! 🚀