Skip to content

Instantly share code, notes, and snippets.

@farishan
Created February 13, 2023 10:33
Show Gist options
  • Select an option

  • Save farishan/6ac3cc654a9b58af71ac49de64e9f18a to your computer and use it in GitHub Desktop.

Select an option

Save farishan/6ac3cc654a9b58af71ac49de64e9f18a to your computer and use it in GitHub Desktop.

Revisions

  1. farishan created this gist Feb 13, 2023.
    28 changes: 28 additions & 0 deletions toJson.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    const fs = require('fs')

    /* Configuration */
    const INPUT_PATH = './disciplines.txt'
    const OUTPUT_PATH = './disciplines.json'
    const ENCODING = 'utf-8'
    const MINIFIED = false
    const SPACE = 2
    const REPLACER = undefined

    fs.readFile(INPUT_PATH, ENCODING, (err, data) => {
    if (err) {
    console.log(err)
    console.log('error.')
    } else {
    console.log(data.split(','))
    const json = MINIFIED ?
    JSON.stringify(data.split(','))
    : JSON.stringify(data.split(','), REPLACER, SPACE)
    fs.writeFile(OUTPUT_PATH, json, function (err) {
    if (err) {
    console.log(err)
    console.log('error.')
    }
    })
    console.log('done.')
    }
    })