Enhancement: Option for single-entry data files #328

Closed
opened 2026-10-05 02:40:26 +02:00 by adam · 2 comments
Owner

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

Some of the data in my site is organized into folders where each file is a different object. I do this because each object can be fairly large on its own, and I find this easier to reason about/review/track. The data dashboard only allows me to define data files that are arrays of the defined type.

Take for example this configuration (simplified, my actual schema and data is longer):

"frontMatter.data.folders": [
  {
    "id": "Testable",
    "path": "[[workspace]]/data/tests",
    "labelField": "name",
    "schema": {
      "title": "Test Files",
      "type": "object",
      "properties": {
        "name": {
          "title": "Entry Name",
          "type": "string"
        },
        "example": {
          "title": "Example data",
          "type": "string"
        }
      }
    }
  }
]

And the data file I want:

name: This is a shortened example.
example: |
  This is a long and busy bunch of text,
  many lines. Normally, there's several
  other properties here too, so the data
  for a single entry might be 150+ lines
  long.

Describe the solution you'd like

I would like an additional key, perhaps flat (to not conflict with the existing single for strings) which would mark a data folder (or file) as a single object, not an array of objects.

For example:

"frontMatter.data.folders": [
  {
    "id": "Testable",
    "path": "[[workspace]]/data/tests",
    "labelField": "name",
    "flat": true,
    "schema": {
      "title": "Test Files",
      "type": "object",
      "properties": {
        "name": {
          "title": "Entry Name",
          "type": "string"
        },
        "example": {
          "title": "Example data",
          "type": "string"
        }
      }
    }
  }
]

Describe alternatives you've considered

Instead of requiring an additional key, omitting labelField could mark a file as being flat/a single object. I like this less since it isn't as clear/explicit and could be confusing for users.

It could also be implemented to require that data files define their schema as an array of objects, but that would break backwards compatibility and be worse DevX I think, since the list behavior is probably the default expectation.

Additional context

Another use case for this, beyond my specific data files, would be configuration files. Config files are typically single objects too. That would allow me to schematize and provide a UI for updating the configuration files in my project.

**Is your feature request related to a problem? Please describe.** Some of the data in my site is organized into folders where each file is a different object. I do this because each object can be fairly large on its own, and I find this easier to reason about/review/track. The data dashboard only allows me to define data files that are arrays of the defined type. Take for example this configuration (simplified, my actual schema and data is longer): ```json "frontMatter.data.folders": [ { "id": "Testable", "path": "[[workspace]]/data/tests", "labelField": "name", "schema": { "title": "Test Files", "type": "object", "properties": { "name": { "title": "Entry Name", "type": "string" }, "example": { "title": "Example data", "type": "string" } } } } ] ``` And the data file I want: ```yaml name: This is a shortened example. example: | This is a long and busy bunch of text, many lines. Normally, there's several other properties here too, so the data for a single entry might be 150+ lines long. ``` **Describe the solution you'd like** I would like an additional key, perhaps `flat` (to not conflict with the existing `single` for strings) which would mark a data folder (or file) as a single object, not an array of objects. For example: ```json "frontMatter.data.folders": [ { "id": "Testable", "path": "[[workspace]]/data/tests", "labelField": "name", "flat": true, "schema": { "title": "Test Files", "type": "object", "properties": { "name": { "title": "Entry Name", "type": "string" }, "example": { "title": "Example data", "type": "string" } } } } ] ``` **Describe alternatives you've considered** Instead of requiring an additional key, omitting `labelField` could mark a file as being flat/a single object. I like this less since it isn't as clear/explicit and could be confusing for users. It could also be implemented to require that data files define their schema as an array of objects, but that would break backwards compatibility and be worse DevX I think, since the list behavior is probably the default expectation. **Additional context** Another use case for this, beyond my specific data files, would be configuration files. Config files are typically single objects too. That would allow me to schematize and provide a UI for updating the configuration files in my project. <!-- github-sync-id:1368721877 -->
adam closed this issue 2026-10-05 02:40:26 +02:00
Author
Owner

Named the new property singleEntry as that makes it a bit clearer. When this is added to folder or file level, you can expect the data dashboard to load the file as follows:

Screenshot 2022-09-27 at 13 09 37

Example configuration:

{
	"frontMatter.data.files": [
	    {
	      "id": "singleEntry",
	      "title": "Single entry",
	      "file": "[[workspace]]/data/single-entry.json",
	      "labelField": "name",
	      "singleEntry": true,
	      "schema": {
	        "title": "Test Files",
	        "type": "object",
	        "properties": {
	          "name": {
	            "title": "Entry Name",
	            "type": "string"
	          },
	          "example": {
	            "title": "Example data",
	            "type": "string"
	          }
	        }
	      }
	    }
	],
	"frontMatter.data.folders": [
    {
      "id": "Testable",
      "path": "[[workspace]]/data/tests",
      "labelField": "name",
      "singleEntry": true,
      "schema": {
        "title": "Test Files",
        "type": "object",
        "properties": {
          "name": {
            "title": "Entry Name",
            "type": "string"
          },
          "example": {
            "title": "Example data",
            "type": "string"
          }
        }
      }
    }
  ]
}

PS: Available to test out in the latest beta version.

Named the new property `singleEntry` as that makes it a bit clearer. When this is added to folder or file level, you can expect the data dashboard to load the file as follows: ![Screenshot 2022-09-27 at 13 09 37](https://user-images.githubusercontent.com/2900833/192510541-d57c1d1c-7f37-4c58-ba53-91029c021ec3.png) Example configuration: ```json { "frontMatter.data.files": [ { "id": "singleEntry", "title": "Single entry", "file": "[[workspace]]/data/single-entry.json", "labelField": "name", "singleEntry": true, "schema": { "title": "Test Files", "type": "object", "properties": { "name": { "title": "Entry Name", "type": "string" }, "example": { "title": "Example data", "type": "string" } } } } ], "frontMatter.data.folders": [ { "id": "Testable", "path": "[[workspace]]/data/tests", "labelField": "name", "singleEntry": true, "schema": { "title": "Test Files", "type": "object", "properties": { "name": { "title": "Entry Name", "type": "string" }, "example": { "title": "Example data", "type": "string" } } } } ] } ``` PS: Available to test out in the latest beta version. <!-- github-comment-id:1259351766 -->
Author
Owner

@estruyf tested on my primary site and it works a treat!

@estruyf tested on my primary site and it works a treat! <!-- github-comment-id:1264562279 -->
Sign in to join this conversation.
No labels
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: adam/vscode-front-matter#328