API for a array of objects, unclear documentation on API
See original GitHub issueI have a array objects like this
[
{
"id": 1,
"name": "Abc Def",
"semester": 1,
"fees": "Paid"
},
{
"id": 2,
"name": "Qwe Rty",
"semester": 3,
"fees": "Pending"
},
{
"id": 3,
"name": "Qwe Rty",
"semester": 3,
"fees": "Pending"
}
]
When I try to use it as a api, it auto converts it to a object and adds a key to each object. How do I even read this?
My students.json array is converted to a object with keys(numbers increamented).
What do I do to get the array instead of a object, how do I access a specific object say student 2 or object 2
from my array.
How do I query this data, like only
or where
and sortBy
, is it also possible to paginate the data (my array of students, eventually it will be crossing 200 students with each object containing more details)
I tried adding querying with only
like this http://localhost:3000/api/students?only=title
it responds with empty object
I might be trying to use it the wrong way, but this would solve me a lot of problems, like instead of using a Headless CMS via its api, everything will be handled locally
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:10
Top GitHub Comments
I’m encountering the same issue with multiple “mono JSON files” containing an array of objects.
Create one file per entry is not always the right solution. In my case, that’s a lot of small objects and it would be way overkill to split them into distinct files.
It would be great to support this type of structure in
nuxt/content
in order to use its great features such as queries.@mathieunicolas sorry my fault, I missed the truthy check for
data[key].id
in your second example. 😃