Need advice on JSON field
![No Code Creations](https://us.v-cdn.net/6037124/uploads/userpics/O3Q4XD9SYAFD/nAXW6G69F164D.png)
Hello everyone!
I am new to Xano and using code as well but I need to learn so here I am.
I have a database that has a list of weeks in them and then a JSON field that will sort a list of "splits", Inside each split is a list of "exercises" and inside each exercise is a list of "sets" (along with other information too).
What I am trying to do is that the user can select how many splits, exercise, and sets, and then the JSON will create it. The users need to be able to record reps and weight on the front end that will then be saved to a database or in the best place.
Can someone talk me through how to make this happen?
Currently have this JSON
{
"workout_splits": [
{
"exercise": {
"exercise_name": "Exercise 1",
"sets": [
{
"reps": 10,
"weight": "50 lbs"
},
{
"reps": 12,
"weight": "55 lbs"
},
{
"reps": 8,
"weight": "45 lbs"
}
]
}
},
{
"exercise": {
"exercise_name": "Exercise 2",
"sets": [
{
"reps": 10,
"weight": "60 lbs"
},
{
"reps": 12,
"weight": "65 lbs"
},
{
"reps": 8,
"weight": "55 lbs"
}
]
}
}
// Add more workout splits and exercises as needed based on trainer's input
]
}
But am lost on how to make it dynamic based on the users selection on how many split, exercises or sets
Answers
-
Instead of thinking in JSON terms, think in a combination of arrays (lists) and objects. You have all kinds of functions and filters to manipulate arrays and objects in Xano, and you can even convert objects into arrays and viceversa if you need to. You can transform anything from/to JSON too.
Functions:
https://docs.xano.com/working-with-data/functions/data-manipulation/arrays
https://docs.xano.com/working-with-data/functions/data-manipulation/objects
Filters:
https://docs.xano.com/working-with-data/data-type-filters/array-filter
https://docs.xano.com/working-with-data/data-type-filters/manipulation-filters
This snippet plays with JSON, arrays, and objects. It might help you watch the video.
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback