Public
Edited
Oct 30, 2023
Insert cell
Insert cell
viewof input = Inputs.textarea({
placeholder:
"Paste in a bunch of newline separated blocks of Twitter debug JSON"
})
Insert cell
html`<textarea style="width: 100%; height: 10em">${JSON.stringify(
tweets
)}</textarea>`
Insert cell
blocks = input.split(/\n+/).map((line) => JSON.parse(line))
Insert cell
entries = {
let temp = [];
blocks.forEach((block) => {
block.data.threaded_conversation_with_injections_v2.instructions.forEach(
(instruction) => {
if (instruction.entries) {
temp.push(...instruction.entries);
}
}
);
});
return temp;
}
Insert cell
tweets = {
let temp = [];
entries.forEach((entry) => {
temp.push(...extractLegacyObjects(entry));
});
let filtered = temp.filter((e) => e.conversation_id_str);
return filtered;
}
Insert cell
function extractLegacyObjects(obj) {
let legacyObjects = [];

function traverse(current) {
if (Array.isArray(current)) {
current.forEach((item) => traverse(item));
} else if (current !== null && typeof current === "object") {
if (
current.hasOwnProperty("legacy") &&
typeof current.legacy === "object"
) {
legacyObjects.push(current.legacy);
}
Object.values(current).forEach((value) => traverse(value));
}
}

traverse(obj);
return legacyObjects;
}
Insert cell
extractLegacyObjects(entries[0])
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more