Skip to content

Feature: add optional startup warning when db contains primitive arrays as resources #1765

@tamjid14

Description

@tamjid14

Feature proposal

When a top-level resource in db.json is an array of primitive values, such as strings or numbers, json-server can produce confusing behavior because resources usually need to be arrays of objects with id fields.

Example:

{
  "roles": ["role-1", "role-2"]
}

This can lead to errors such as trying to create an id property on a string.

Suggested behavior

json-server could show a clear startup warning when a top-level resource contains primitive array items:

Warning: "roles" contains primitive values. Resources should usually be arrays of objects with id fields.

Why this helps

This would make the error easier to understand for beginners and would point users toward the expected structure:

{
  "roles": [
    { "id": "role-1", "name": "role-1" },
    { "id": "role-2", "name": "role-2" }
  ]
}

This feature would not need to block startup. A warning may be enough to help users fix their database structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions