S
S
Stanislav2015-10-26 23:14:08
Node.js
Stanislav, 2015-10-26 23:14:08

How to overcome colon in object JSON keys (nconf)?

Using nconf, I get file data for widespread use in the project

nconf

    .add('filename', {

        "type": "file",

        "file": path.join(__dirname, 'filename/myfile.json')

    })

File data
{
    "Widescreen 16:10": {
        "test": 11111
    }
}

At the output in this situation, they get a completely different object.
{
    "Widescreen 16": {
        "10": {
            "test": 11111
         }
    }
}

It is clear that the keys are not called that, but this object stupidly spits out all the contents in a cycle, and if you just load the file through fs, then everything is in order. But if you pull it with the help of nconf, then it seems to bring the object to a more correct form. How to overcome it? Of course, I can make this key a value, and bring the key itself to the correct form, but this is not very convenient in this case =( I would also not want to use a regular with replacing another character with a colon.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
Timur Shemsedinov, 2015-10-26
@ms-dred

Don't use nconf and stuff like that. And load JSON files via var config = requere('config.js'); or via fs and then JSON.parse()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question