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, the content becomes static. To really have dynamic content from a JSON file in your Digital Garden, you need an iframe.