Converting Instagram saved_collections.json file to csv file and importing it to notion

instagram, programming, notion, database, csv, json, Instagram, saved_collections.json

Download Your Instagram Data from the Account Deletion Interface

💡 You will not be deleting your account, you will only proceed to the download my data section

Help Center

Then, extract the saved_collections.json file from the downloaded zip

  • This file keeps your saved collections contents along with your tags

  • We will continue our operations with this file

Converting saved_collections.json file to csv

  • Requires nodejs installation

  • Run the javascript code below in the directory of saved_collections.json

  • Or give the file path to the bottom line of the code

const { readFileSync, writeFileSync } = require("fs")

function jsonToCSV(json) {
	const csvRows = []
	csvRows.push("Name,Time,URL,Channel,Tags")

	for (const [key, value] of Object.entries(json)) {
		const tags = value.tags.join(",")
		const utcTime = value.time.toISOString()
		csvRows.push(`${value.name},${utcTime},${key},${value.channel},"${tags}"`)
	}

	return csvRows.join("\\n")
}

function instagramCollectionToCSV(inputPath) {
	const content = JSON.parse(readFileSync(inputPath))

	const data = {}
	let tag = undefined
	content.saved_saved_collections.forEach(collection => {
		const url = collection.string_map_data.Name.href
		if (url === undefined) {
			const rawTag = collection.string_map_data.Name.value
			tag = Buffer.from(rawTag, "binary").toString("utf8")
			return
		}

		const name = url.split("/").slice(-2)[0]
		const time = new Date(collection.string_map_data["Added Time"].timestamp * 1000)
		const channel = collection.string_map_data.Name.value

		if (!data[url]) {
			data[url] = { channel, tags: [], time, name }
		}
		if (tag && !data[url].tags.includes(tag)) {
			data[url].tags.push(tag)
		}
	})

	const csv = jsonToCSV(data)
	const outputPath = path.replace(".json", ".csv")
	writeFileSync(outputPath, csv)
}

const path = "./saved_collections.json"
instagramCollectionToCSV(path)

Importing the csv file onto Notion

Use the `import - csv` interface

Formatting Notion data

Keep `channel` data as `select`
Store `Tags` part as `multi select`

- The `csv` file is prepared to be suitable for automatic formatting - As soon as you do `multi select`, your `tags` values will match

Last updated

© 2024 ~ Yunus Emre Ak ~ yEmreAk