JSON
Parsing JSON
import json
struct Customer {
first_name string
last_name string
hometown string
}
fn main() {
customers_string := '[{ "first_name": "Vitor", "last_name": "Oliveira", "hometown": "Rio de Janeiro" }, { "first_name": "Don", "last_name": "Nisnoni", "hometown": "Kupang" }]'
customers := json.decode([]Customer, customers_string) or {
eprintln('Failed to parse json')
return
}
// Print the list of customers
for customer in customers {
println('$customer.first_name $customer.last_name: $customer.hometown')
}
}Generating JSON
Exercises
Last updated
Was this helpful?