In my special use case, I import JSON file and use them as functions.
For example,
import validator from './example.schema.json'; // schema JSON imported as function
import data from './data.json'; // general JSON imported as data
console.log(data); // { value: 'random-data' }
validator(data);To achieve this in Vite, we had to override its internal json plugin with ours.
So that normal JSON files would be imported as usual. While JSON files named as .schema.json can be used as functions.