JSON alternatives (for the purpose of specifying configuration)?

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

    The EDN format is one option based on Clojure literals. It is almost a superset of JSON, except that no special symbol separates keys and values in maps (as : does in JSON); rather, all elements are separated by whitespace and/or a comma and a map is encoded as a list with an even number of elements, enclosed in {..}.

    EDN allows for comments (to newline using ;, or to end of the next element read using #_), but not here-docs. It is extensible to new types using a tag notation:

    #myapp/Person {:first "Fred" :last "Mertz"}
    

    The argument of the myapp/Person tag (i.e. {:first "Fred" :last "Mertz"}) must be a valid EDN expression, which makes it unextensible to here-doc support.

    It has two built-in tags: #inst for timestamps and #uuid. It also supports namespaced symbol (i.e. identifier) and keyword (i.e. map key consts) types; it distinguishes lists (..) and vectors [..]. An element of any type may be used as a key in a map.

    In the context of your above problem, one could invent an #apache/rule-or tag which accepts a sequence of elements, whose semantics I leave up to you!

提交回复
热议问题