JSON alternatives (for the purpose of specifying configuration)?

后端 未结 8 2554
悲&欢浪女
悲&欢浪女 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:43

    The 'J' in JSON is "Javascript". If a particular desired syntax construct isn't in Javascript, then it won't be on JSON.

    Heredocs are beyond JSON's purview. That's a language syntax construct for simplified multi-line string definition, but JSON is a transport notation. It has nothing to do with construction. It does, however, have multiline strings, simply by allowing \n newline characters within strings. There's nothing in JSON that says you can't have a linebreak in a string. As long as the containing quote characters are correct, it's perfectly valid. e.g.

    {"x":"y\nz"}
    

    is 100% legitimate valid JSON, and is a multiline string, whereas

    {"x":"y
    z"} 
    

    isn't and will fail on parsing.

提交回复
热议问题