I'd go with a JS Code block that lets you define the JSON and put the various variables you've collected in your form into the appropriate objects:
// Define variables - these will actually come from your form
var id = 1; // form.id
var name = "John Smith"; // form.name
var pin = 493746; // etc.
var latitude = 37.7749;
var longitude = -122.4194;
// Create the JSON object
var desiredJSON= {
"student": {
"id": id,
"name": name,
"address": {
"city": {
"nearby_town": {
"pin": pin
}
},
"coordinates": {
"latitude": latitude,
"longitude": longitude
}
}
}
};
return desiredJSON