Skip to content

Add JSON array of objects support (mono-files) #480

@monsieurnebo

Description

@monsieurnebo

Is your feature request related to a problem? Please describe.

This package is made to process data from a "one file = one entry" principle:

content/
  articles/
    article-1.json
    article-2.json
  home.json

While this structure makes sense for articles and/or pages where each entry contains a lot of data, this is not always the case.

Let's take for example a huge list of employees where each entry contains only a few keys. The management of this data is easier in a single JSON file, in the form of an object table:

// content/employees.json
[
  {
    "name"       : "Philippe Etchebest",
    "picture"    : "philippe-etchebest.jpg",
    "position"   : "Chef"
  }, {
    //...
  }
]

Describe the solution you'd like

I would expect that nuxt/content process this array as a data source, allowing me to use queries on it. Fore instance:

const employees = $content("employees").where({ position: { $ne: "Chef" } }).fetch();

Giving us the opportunity to use a JSON mono-file, containing an array of objects where "one object = one entry".

Describe alternatives you've considered

The alternative would be:

  • Use JS module import instead, and native Array methods (find, filter, ...)
  • Change our data structure to fit the current nuxt/content philosophy

Additional context

Related issues:
#112
#36

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions