Skip to content

Instantly share code, notes, and snippets.

@alextanhongpin
Created July 12, 2017 05:51
Show Gist options
  • Save alextanhongpin/372072dcbc1ac74902d9036d54779bc5 to your computer and use it in GitHub Desktop.
Save alextanhongpin/372072dcbc1ac74902d9036d54779bc5 to your computer and use it in GitHub Desktop.
JSON object to Markdown table
const data = require('./data/jobs.json')
const fs = require('fs')
const jobs = data.jobs.recordsets[0]
const d = jobs.reduce((obj, job) => {
Object.keys(job).map((j) => {
if (!obj[j]) {
obj[j] = job[j]
}
})
return obj
}, {})
fs.writeFile('./data/job.json', JSON.stringify(d), (err, ok) => {
console.log(err, ok)
})
// Convert to readme file
const keys = Object.keys(d)
let readme = `
| Field | Type | Value |
|-------|------|-------|
`
keys.map((key) => {
readme += `| ${key} | ${typeof d[key]} | ${d[key]} |\n `
})
console.log(readme)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment