There are many websites that explain what a JSON is like, but I’ve found none that explains what a JSON “should” be like. I’m talking about better practices.
To be more specific on my question: I’m requesting the data of a week(for a reservation system) using the Ajax technique and currently this is what I’m sending back(I’ve omitted some days and some times for the sake of brevity):
{
"week":
[
{
"stamp": 1234567890,
"dayName": "sunday",
"date": "July 25th",
"times":
[
{
"state": "past",
"price": 20,
"time-number": 1,
"time-span": "08:00 to 09:30"
},
{
"state": "free",
"price": 40,
"time-number": 2,
"time-span": "09:30 to 11:00"
},
{
"state": "reserved",
"price": 30,
"time-number": 3,
"time-span": "11:00 to 12:30"
}
]
},
{
"stamp": 1234561234,
"dayName": "monday",
"date": "July 26th",
"times":
[
{
"state": "free",
"price": 20,
"time-number": 1,
"time-span": "08:00 to 09:30"
},
{
"state": "reserved",
"price": 45,
"time-number": 2,
"time-span": "09:30 to 11:00"
},
{
"state": "free",
"price": 30,
"time-number": 3,
"time-span": "11:00 to 12:30"
}
]
}
]
}
Now my questions are:
-
This is the arrangement that makes the most sense to me. However, doesn’t it have any problems/weaknesses according to your experience? (I specially ask this because in the JavaScript side I’ve come up with writing something which is a bit long to me
to fill the table fields)
-
Since all the time spans are the same for all days of week, should I still send the time-span like this(isn’t it redundant?), or I should put another key value at the end of my JSON to specify it and that would be enough?
-
What level of nested-ness is common/usual/not-weird! in a JSON arrangement?
-
Do I really need to specify that this is the “week” information at the beginning? I looked at some JSON samples on the Internet and felt like it’s needed to be there. Maybe it makes the sent data even more readable(?).
Thank you in advance.