JSON替代品(出于指定配置的目的)? [英] JSON alternatives (for the purpose of specifying configuration)?

查看:130
本文介绍了JSON替代品(出于指定配置的目的)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢json作为我编写的软件的配置文件格式.我喜欢它轻巧,简单并且得到广泛支持.但是,我发现json中确实有一些我不想要的东西.

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 things I'd really like in json that it doesn't have.

Json没有多行字符串或此处的文档( http://en.wikipedia.org/wiki /Here_document ),并且当您希望json文件具有人类可读性和可编辑性时,这通常很尴尬.您可以使用字符串数组,但这是一种繁杂的解决方法.

Json doesn't have multiline strings or here documents ( http://en.wikipedia.org/wiki/Here_document ), and that is often very awkward when you want your json file to be human-readable and -editable. You can use arrays of strings, but that's a kludgy workaround.

Json不允许评论.

Json doesn't allow comments.

如果您查看unix配置文件的格式,就会发现很多人为自己的尴尬格式设计东西,而使用某种通用用途的东西确实更有意义.例如,这是来自Apache配置文件的一些代码:

If you look at the formats of unix configuration files, you see a lot of people designing their own awkward formats for things that it would really make more sense to do using some kind of general-purpose thing. For example, here's some code from an Apache config file:

RewriteEngine on
RewriteBase /temp
RewriteCond %{HTTP_ACCEPT} application/xhtml\+xml
RewriteCond %{HTTP_ACCEPT} !application/xhtml\+xml\s*;\s*q=0
RewriteCond %{REQUEST_URI} \.html
RewriteCond %{THE_REQUEST} HTTP/1\.1
RewriteRule t\.html t.xhtml [T=application/xhtml+xml]

从本质上讲,这是他们发明了一种非常痛苦的方式来编写布尔函数f(w,x,y,z)= w&!x& y& z.您想要逻辑上的或"吗?他们也有一些单独的(丑陋的)机制.

Essentially, what's going on here is that they've invented an extremely painful way of writing a boolean function f(w,x,y,z)=w&!x&y&z. You want a logical "or"? They've got some separate (ugly) mechanism for that, too.

这似乎指向的是一种简单且图灵不完整的数据描述语言,但比json更具表达性,灵活性和便利性.有人知道这种语言吗?

What this seems to point toward is some kind of data description language that is simple and Turing-incomplete, but still more expressive, flexible, and convenient than json. Does anyone know of such a language?

以我的喜好,XML太复杂了,而Lisp表达式具有错误的特征(图灵完整性)而缺乏正确的特征(此处为文档,表达语法).

To my taste, XML is too complicated, and lisp expressions have the wrong features (Turing-completeness) and lack the right features (here documents, expressive syntax).

标题具有误导性.我实际上对json的下一次迭代不感兴趣.我对javascript的一部分语言不感兴趣.我对其他数据描述语言感兴趣.

The title is misleading. I'm not literally interested in the next iteration of json. I'm not interested in languages that are a subset of javascript. I'm interested in alternative data-description languages.

推荐答案

看看 http://igagis.github.io/stob/

它甚至比JSON更简单.

It is even simpler than JSON.

它具有C ++样式的注释.

It has C++ style comments.

如果需要真实的"新行或制表符,则可以格式化多行字符串并使用转义的新行\ n和制表符\ t字符.

It is possible to format multiline strings and use escaped new line \n and tab \t chars if "real" new line or tab is needed.

以下是示例代码段:

"String object"
AnotherStringObject
"String with children"{
    "child 1"
    Child2
    "child three"{
        SubChild1
        "Subchild two"

        Property1 {Value1}
        "Property two" {"Value 2"}
        //comment

        /* multi-line
           comment */

        "multi-line
         string"

        "Escape sequences \" \n \r \t \\"
    }

R"qwerty(
This is a
raw string, "Hello world!"
int main(argc, argv){
    int a = 10;
    printf("Hello %d", a);
}
)qwerty"
}

这篇关于JSON替代品(出于指定配置的目的)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆