Public
Edited
Nov 15, 2022
Insert cell
Insert cell
s = `"{\"@context\":[\"https://www.w3.org/ns/activitystreams\",\"https://w3id.org/security/v1\",{\"manuallyApprovesFollowers\":\"as:manuallyApprovesFollowers\",\"sensitive\":\"as:sensitive\",\"Hashtag\":\"as:Hashtag\",\"movedTo\":{\"@id\":\"as:movedTo\",\"@type\":\"@id\"},\"alsoKnownAs\":{\"@id\":\"as:alsoKnownAs\",\"@type\":\"@id\"},\"toot\":\"http://joinmastodon.org/ns#\",\"Emoji\":\"toot:Emoji\",\"featured\":{\"@id\":\"toot:featured\",\"@type\":\"@id\"},\"featuredTags\":{\"@id\":\"toot:featuredTags\",\"@type\":\"@id\"},\"schema\":\"http://schema.org#\",\"PropertyValue\":\"schema:PropertyValue\",\"value\":\"schema:value\",\"ostatus\":\"http://ostatus.org#\",\"atomUri\":\"ostatus:atomUri\",\"inReplyToAtomUri\":\"ostatus:inReplyToAtomUri\",\"conversation\":\"ostatus:conversation\",\"focalPoint\":{\"@container\":\"@list\",\"@id\":\"toot:focalPoint\"},\"blurhash\":\"toot:blurhash\",\"discoverable\":\"toot:discoverable\",\"votersCount\":\"toot:votersCount\",\"Device\":\"toot:Device\",\"Ed25519Signature\":\"toot:Ed25519Signature\",\"Ed25519Key\":\"toot:Ed25519Key\",\"Curve25519Key\":\"toot:Curve25519Key\",\"EncryptedMessage\":\"toot:EncryptedMessage\",\"publicKeyBase64\":\"toot:publicKeyBase64\",\"deviceId\":\"toot:deviceId\",\"claim\":{\"@type\":\"@id\",\"@id\":\"toot:claim\"},\"fingerprintKey\":{\"@type\":\"@id\",\"@id\":\"toot:fingerprintKey\"},\"identityKey\":{\"@type\":\"@id\",\"@id\":\"toot:identityKey\"},\"devices\":{\"@type\":\"@id\",\"@id\":\"toot:devices\"},\"messageFranking\":\"toot:messageFranking\",\"messageType\":\"toot:messageType\",\"cipherText\":\"toot:cipherText\",\"suspended\":\"toot:suspended\"}],\"id\":\"https://mastodon.me.uk/users/revbingo/statuses/109349448133183990/activity\",\"type\":\"Create\",\"actor\":\"https://mastodon.me.uk/users/revbingo\",\"published\":\"2022-11-15T19:22:43Z\",\"to\":[\"https://www.w3.org/ns/activitystreams#Public\"],\"cc\":[\"https://mastodon.me.uk/users/revbingo/followers\",\"https://fedi.simonwillison.net/users/simon\"]"`
Insert cell
html`<textarea>${s}<textarea>`
Insert cell
viewof input = Inputs.textarea({ placeholder: "Paste JSON here", rows: 10 })
Insert cell
{
if (input.trim() == "") {
return html``;
}
if (output && output.error) {
return html`<span style="color: red">${output.error}</span>`;
} else {
return html`Decoded:<pre>${JSON.stringify(output, null, 2)}</pre>`;
}
}
Insert cell
root = {
try {
return JSON.parse(input);
} catch (e) {
return { error: e.toString() };
}
}
Insert cell
function decodeRecursively(obj) {
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch {
return obj;
}
} else if (typeof obj === "object") {
for (const key in obj) {
obj[key] = decodeRecursively(obj[key]);
}
}
return obj;
}
Insert cell
output = decodeRecursively(root)
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