Published
Edited
Nov 12, 2021
3 stars
Insert cell
Insert cell
String(launches[0].fairings)
Insert cell
Insert cell
launches = FileAttachment("launches.json").json()
Insert cell
Inputs.table(launches)
Insert cell
Insert cell
table(launches)
Insert cell
Insert cell
stringify(launches)
Insert cell
stringify(launches[0])
Insert cell
stringify(launches[0].fairings)
Insert cell
Insert cell
stringify(launches[0], {keysToShow: 2, charsToShow: 4})
Insert cell
Insert cell
function stringify(
obj,
{ showValues = true, keysToShow = 3, charsToShow = 10 } = {}
) {
if (!obj || typeof obj !== "object" || obj instanceof Date) return obj;
if (Array.isArray(obj)) {
if (obj.length === 0) return "[]";
return `${obj.length} × ${stringify(obj[0], { showValues: false })}`;
}
const keys = Object.keys(obj);
return `{${keys
.slice(0, keysToShow)
.map(
showValues
? (key) => {
const str = String(stringify(obj[key]));
return `${key}: ${str.substring(0, charsToShow)}${
str.length > charsToShow ? "…" : ""
}`;
}
: (d) => d
)
.join(", ")}${keys.length > keysToShow ? ", …" : ""}}`;
}
Insert cell
table = (data, { keysToShow = 2, charsToShow = 5 } = {}) =>
Inputs.table(data, {
format: Object.fromEntries(
Object.keys(data[0]).map((key) => [
key,
(d) => stringify(d, { keysToShow, charsToShow })
])
)
})
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