MCPcopy Create free account
hub / github.com/Datakitpage/Datakit / downloadJSON

Function downloadJSON

frontend/src/utils/exportUtils.ts:115–141  ·  view source on GitHub ↗
(
  data: any, 
  filename: string = 'DataKit_Export',
  extension: string = 'json'
)

Source from the content-addressed store, hash-verified

113 * Download JSON data as a file
114 */
115export const downloadJSON = (
116 data: any,
117 filename: string = 'DataKit_Export',
118 extension: string = 'json'
119): void => {
120 try {
121 // Use specific MIME type for Jupyter notebooks
122 const mimeType = extension === 'ipynb'
123 ? 'application/x-ipynb+json'
124 : 'application/json';
125
126 const blob = new Blob([JSON.stringify(data, null, 2)], {
127 type: mimeType
128 });
129 const url = URL.createObjectURL(blob);
130 const a = document.createElement('a');
131 a.href = url;
132 a.download = `${filename}.${extension}`;
133 document.body.appendChild(a);
134 a.click();
135 document.body.removeChild(a);
136 URL.revokeObjectURL(url);
137 } catch (error) {
138 console.error('Failed to download JSON:', error);
139 throw new Error('JSON download failed. Please try again.');
140 }
141};
142
143/**
144 * Download text content as a file

Callers 2

exportQueryAsJSONFunction · 0.90
exportAsJupyterNotebookFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected