Access JSON data from Obsidian
If you want to access a JSON file from a remote server in Obsidian, DataviewJS is your friend. You have to rely on the requestUrl() method, though, as a classic fetch() fails because of CORS (Cross-Origin Resource Sharing). Another option, dv.io.load() from Dataview, can only handle local files.
const { requestUrl } = require('obsidian');
const options = {
url: 'https://your-server/data.json',
method: 'GET',
};
requestUrl(options).then(response => {
const data = JSON.parse(response.text);
dv.paragraph(data)
})
.catch(error => {
dv.paragraph('Error loading file:', error);
});
The function gets executed every time the page is displayed in Obsidian. However, when you publish the page to the Digital Garden via the Obsidian plugin, the note content becomes static. To really have dynamic content (e.g. from a JSON file) in your Digital Garden notes, you can go with the iframe solution.