hjson-js
hjson-js copied to clipboard
delete object property
I would like to be able to delete an object property via the delete keyword:

When I do that with hjson, the property is set to undefined.
See example
const path = require('path')
const promisify = require('promisify-node')
const fs = promisify('fs')
const hjson = require('hjson')
const CONFIGFILE = path.resolve(__dirname, '../serverconfig.hjson')
async function get() {
const file = await fs.readFile(CONFIGFILE)
return hjson.rt.parse(file.toString())
}
async function set(config) {
const json = hjson.rt.stringify(config, {
quotes: 'strings',
space: 4, // can also use \t for tabs
bracesSameLine: true,
})
await fs.writeFile(CONFIGFILE, json)
}
(async () => {
var x = await get()
delete x.example
await set(x)
// hjson file still contains `example` property
})()
I don't have time to look at it now but I guess it's a bug with round-tripping the comments. If you don't need that feature you can use hjson.stringify().