Platform
Resources
Pricing
Sign in
Get started
Simon Willison
Workspace
Fork
Published
By
Simon Willison
Edited
Jan 31, 2022
Insert cell
Insert cell
Insert cell
html
`That TOML as JSON:<br>
<pre>${
escapeHtml
(
jsonified
)
}</pre>`
Insert cell
jsonified
=
JSON
.
stringify
(
parsed
,
// The TOML library returns big integers - convert those to regular integers
// Note this will break with integers larger than 2^53 - 1
(
key
,
value
)
=>
typeof
value
===
"bigint"
?
parseInt
(
value
.
toString
(
)
,
10
)
:
value
,
4
)
Insert cell
parsed
=
toml
.
parse
(
text
)
Insert cell
Insert cell
toml
=
require
(
"@ltd/j-toml"
)
Insert cell
function
escapeHtml
(
unsafe
)
{
return
unsafe
.
replace
(
/&/g
,
"&"
)
.
replace
(
/</g
,
"<"
)
.
replace
(
/>/g
,
">"
)
.
replace
(
/"/g
,
"""
)
.
replace
(
/'/g
,
"'"
)
;
}
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.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
text
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jsonified
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
parsed
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
toml
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
escapeHtml
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML