You are on page 1of 1

const jsonData = document.getElementById('__NEXT_DATA__').

innerHTML
const json = JSON.parse(jsonData);
const complementaryInfo = {
folderId: null,
icon: null,
name: json.props.pageProps.publishedTypebot.typebot.name,
publicId: json.props.pageProps.publishedTypebot.typebot.publicId,
resultsTablePreferences: null,
isArchived: json.props.pageProps.publishedTypebot.typebot.isArchived,
isClosed: json.props.pageProps.publishedTypebot.typebot.isClosed,
selectedThemeTemplateId: null,
customDomain: null,
}

const formatedJson =
{ ...json.props.pageProps.publishedTypebot, ...complementaryInfo };

delete formatedJson.typebot;
delete formatedJson.typebotId;

const fileName = window.location.pathname || 'copy';


const data = "text/json;charset=utf-8," +
encodeURIComponent(JSON.stringify(formatedJson, null, 2));
const a = document.createElement('a');
a.href = 'data:' + data;
a.download = `typebot-${fileName.replace('/', '')}.json`;
a.innerHTML = 'download JSON';

document.body.appendChild(a);
a.click();
a.remove();

You might also like