question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

API for a array of objects, unclear documentation on API

See original GitHub issue

I 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).

response

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 image

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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

1reaction
monsieurnebocommented, Sep 14, 2020

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.

0reactions
dtmzrcommented, Jun 7, 2020

@mathieunicolas sorry my fault, I missed the truthy check for data[key].id in your second example. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

API Design: Undocumented object keys vs. Array of Objects
1. Undocumented object keys · PROS: Very clean, easy for application logic to parse · CONS: This object can't be documented properly -...
Read more >
OpenAPI Specification - Version 3.0.3 - Swagger
The OpenAPI Specification defines a standard interface to RESTful APIs which allows both humans and computers to understand service capabilities without ...
Read more >
Purpose and scope — Python array API standard 2021.12 ...
This document aims to standardize functionality that exists in most/all array libraries and either is commonly used or is needed for consistency/completeness.
Read more >
Array.prototype.reduce() - JavaScript - MDN Web Docs
If you decided to mutate the accumulator instead of copying it, remember to still return the modified object in the callback, or the...
Read more >
Array — Godot Engine (stable) documentation in English
The arguments are an object that holds the method and the name of such method. The custom method receives two arguments (a pair...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found