json5 / json5-spec

The JSON5 Data Interchange Format
https://spec.json5.org
MIT License
49 stars 11 forks source link

Dumb idea / question - Type/Schema/Contract Definition for JSON5 Files #52

Closed tomkennedy22 closed 5 months ago

tomkennedy22 commented 5 months ago

Hi all, I'm a JSON5 user and big fan. I'm encountering a small problem - not with JSON5 itself, but with maintaining some datasets in JSON5.

I pull data into Typescript and hope that the underlying datasets have the right structure. I, as the maintainer of my project, can verify the underlying JSON5 files have the right structure. But as I have more contributors, I worry that they might not structure it correctly, and run into problems in the code.

So, I'm just brainstorming, spitballing, etc. I understand my question is far outside the scope of normal JSON5 operations. But does anyone have thoughts/feelings on the ability to define a structure of your data, and have it linted & enforced directly in the JSON file, rather than on data read?

So like my file could look like this, with structure defining types, and data defining data

{
 structure: {
   field_a: number,
   field_b: {
     field_c: number,
     field_d?: string
   }
  }[],
 data: [
 {
    field_a: 5,
    field_b: {field_c: 1: field_d: 'duhh'}
  },
  {
    field_a: 5,
    field_b: {field_c: 1}
  }
 ]
}

And maybe even other metadata fields as well.