Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

delete object property #31

Open
MartinMuzatko opened this issue Nov 24, 2017 · 1 comment
Open

delete object property #31

MartinMuzatko opened this issue Nov 24, 2017 · 1 comment

Comments

@MartinMuzatko
Copy link

I would like to be able to delete an object property via the delete keyword:

image

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
})()
@laktak
Copy link
Member

laktak commented Dec 12, 2017

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().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants