Instantly share code, notes, and snippets.

Embed
What would you like to do?
// source json is
// https://raw.githubusercontent.com/tableflip/libp2p-website/963d50ccb4d586857b85b0f2d35b448a065ca2b0/data/bundles.json
/*
GOAL:
```json
[
{
"name": "Browser JS",
"status": "live",
"image": "../img/logo_1.png",
"github": "https://github.com/ipfs/js-libp2p-ipfs-browser",
"categories": [
{
"name": "Transport" ,
"modules": [
{
"id": "libp2p-websockets",
"status": "Done",
"url": "https://github.com/libp2p/js-libp2p-websockets"
},
{
"id": "libp2p-webrtc-star",
"status": "Done",
"url": "https://github.com/libp2p/js-libp2p-webrtc-star"
}
]
}
]
}
]
```
what we have:
```json
{
"Bundles": {
"Browser JS": {
"status": "live",
"image": "../img/logo_1.png",
"github": "https://github.com/ipfs/js-libp2p-ipfs-browser",
"categories": {
"Transport": {
"modules": {
"libp2p-websockets": {
"status": "Done",
"url": "https://github.com/libp2p/js-libp2p-websockets"
},
"libp2p-webrtc-star": {
"status": "Done",
"url": "https://github.com/libp2p/js-libp2p-webrtc-star"
}
}
}
}
}
}
}
```
*/
const data = require('./bundles.json').Bundles
const res = Object.keys(data).map(langName => {
const lang = data[langName]
const categories = Object.keys(lang.categories || []).map(categoryName => {
const category = lang.categories[categoryName]
const modules = Object.keys(category.modules).map(moduleId => {
const module = category.modules[moduleId]
return {
id: moduleId,
status: module.status,
url: module.url
}
})
return {
name: categoryName,
modules
}
})
return {
name: langName,
status: lang.status,
image: lang.image,
github: lang.github,
categories: categories
}
})
console.log(JSON.stringify(res, null, 2))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment