My backend is built with express (so basically javascript). The backend is also able to save some data to .json files and use this data.
var data = JSON.parse(fs.readFileSync("path/data.json"));
It would help me a lot, if Visual Studio Code would provide Intellisense for my data object (like suggesting all elements of this json file). Is there any addon for this kind of "problem" ?
Example:
{
"owner": "testperson",
"age": "30"
}
After parsing this json file (exact way like on top), it would be very helpful to have Intellisense after writing
data.
There is a built-in solution in VSCode exactly that manner. To get intellisense VSCode needs to know what the type of something is and for that you can use JSDoc comments, if you want to stick to JavaScript. These are understood by VSCode without any problem. The snippet down below is applies to your given example.
/**
* @typedef {Object} MyData
* @property {string} owner
* @property {number} age
*/
/**
* @type {MyData}
*/
let data = JSON.parse(fs.readFileSync("path/data.json"));
For further reading I refer to the JSDoc docs.