JSON alternatives (for the purpose of specifying configuration)?

后端 未结 8 2549
悲&欢浪女
悲&欢浪女 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 21:06

    There is also thindf.

    Although it does not support comments, they can be emulated via empty keys:

    config_var1 = value1
    =some comment
    config_var2 = value2
    
    0 讨论(0)
  • 2021-02-19 21:06

    Since March 2018 you can use JSON5 which seems to have added everything you (& many others) were missing from JSON.

    Short Example (JSON5)

    {
      // comments
      unquoted: 'and you can quote me on that',
      singleQuotes: 'I can use "double quotes" here',
      lineBreaks: "Look, Mom! \
    No \\n's!",
      hexadecimal: 0xdecaf,
      leadingDecimalPoint: .8675309, andTrailing: 8675309.,
      positiveSign: +1,
      trailingComma: 'in objects', andIn: ['arrays',],
      "backwardsCompatible": "with JSON",
    }
    

    The JSON5 Data Interchange Format (JSON5) is a superset of JSON that aims to alleviate some of the limitations of JSON by expanding its syntax to include some productions from ECMAScript 5.1.

    Summary of Features

    The following ECMAScript 5.1 features, which are not supported in JSON, have been extended to JSON5.

    Objects

    • Object keys may be an ECMAScript 5.1 IdentifierName.
    • Objects may have a single trailing comma.

    Arrays

    • Arrays may have a single trailing comma.

    Strings

    • Strings may be single quoted.
    • Strings may span multiple lines by escaping new line characters.
    • Strings may include character escapes.

    Numbers

    • Numbers may be hexadecimal.
    • Numbers may have a leading or trailing decimal point.
    • Numbers may be IEEE 754 positive infinity, negative infinity, and NaN.
    • Numbers may begin with an explicit plus sign.

    Comments

    • Single and multi-line comments are allowed.

    White Space

    • Additional white space characters are allowed.

    GitHub: https://github.com/json5/json5

    0 讨论(0)
提交回复
热议问题