Created
July 12, 2017 05:51
-
-
Save alextanhongpin/372072dcbc1ac74902d9036d54779bc5 to your computer and use it in GitHub Desktop.
JSON object to Markdown table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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