JSON alternatives (for the purpose of specifying configuration)?

后端 未结 8 2399
悲&欢浪女
悲&欢浪女 2021-02-19 20:31

I like json as a format for configuration files for the software I write. I like that it\'s lightweight, simple, and widely supported. However, I\'m finding that there are some

8条回答
  •  遥遥无期
    2021-02-19 20:56

    There's always what I like to call "real JSON". JSON stands for JavaScript Object Notation, and JavaScript does have comments and something close enough to heredocs.

    For the heredoc, you would use JavaScript's E4X inline XML:

    {
        longString: <>
                    Hello, world!
                    This is a long string made possible with the magic of E4X.
                    Implementing a parser isn't so difficult.
                    .toString() // And a comment
        /* And another
           comment */
    }
    

    You can use Firefox's JavaScript engine (FF is the only browser to support E4X currently) or you can implement your own parser, which really isn't so difficult.

    Here's the E4X quickstart guide, too.

提交回复
热议问题