因此,我正在try 记录由我正在编写的API返回的json的格式,我想知道是否有任何流行的json struct 文档格式.

请注意,我并不是想测试或验证任何东西,我只是用它来做文档.还有一些向非常量(项目总是返回相同值)添加注释的方法也不错.

This the not totally thought out scheme I'm currently using:

Plain names refer to identifiers or types.
Some types have type-comment
Strings that appear to be constant(always returned for that type of request) strings are "str"
Constant Numbers would be just the number
Constant null is null
Booleans are true/false for constant booleans or Boolean otherwise
[a,b,c] are lists with 3 items a,b,c
[...  ...] is a list of repeating elements of some types/constants/patterns
{a:A,b:B,c:c} and {... ...}  is the same for a dictionary.

example:

story          := [header,footer]
header         := {"data":realHeader,"kind":"Listing"}
realHeader     := {"after": null, "before": null, "children": [{"data": realRealHeader, "kind": "t3"}], "modhash": ""}
footer         := {"data":AlmostComments,"kind":"Listing"}
AlmostComments := {"data": {"after": null, "before": null, "children": comments, "modhash": ""}, "kind": "t1"}
comments       := [...{"data":comment, "kind":"t1"}...]

realRealHeader :=
{"author": string,
"clicked": boolean,
"created": int,
"created_utc": int,
"domain": "code.reddit.com",
"downs": int,
"hidden": boolean,
"id": string-id,
"is_self": boolean,
"levenshtein": null,
"likes": null,
"media": null,
"media_embed": { },
"name": string-id,
"num_comments": int,
"over_18": false,
"permalink": string-urlLinkToStoryStartingFrom/r,
"saved": false,
"score": int,
"selftext": string,
"selftext_html": string-html,
"subreddit": string-subredditname,
"subreddit_id": string-id,
"thumbnail": "",
"title": string,
"ups": int,
"url": "http://code.reddit.com/"
}


comments := {
"author": string,
"body": string-body_html-wout-html,
"body_html": string-html-formated,
"created": int,
"created_utc": int,
"downs": int,
"id": string-id,
"levenshtein": null,
"likes": null,
"link_id": string-id,
"name": string-id",
"parent_id": string-id,
"replies": AlmostComments or null,
"subreddit": string-subredditname,
"subreddit_id": string-id,
"ups": int
}

推荐答案

理论上JSON Schema可以达到这个目的,但实际上我不确定它是否能达到.我希望值得一提.

除此之外,我个人的观点是,由于JSON主要用于传输对象,以客户机使用的语言(Java、C#、各种脚本语言)记录等价的对象可能最有意义--毕竟,此类对象通常映射/绑定到JSON,然后再映射/绑定到JSON.然后,您可以使用任何可用的文档工具,比如Java的Javadoc(Perl的perldoc、c++的O2等等).

For specifying interfaces there is also WADL (Web App Description Language), which might help.

Json相关问答推荐

JOLT转换,将属性复制到同级别的dict中

如何抓住引号之间的第二次出现?

在T—SQL中将STR_AGG与JSON_ARRAY结合起来

从先前的REST调用创建动态JSON主体

解析JSON说函数parse_json不存在?

使用jq过滤复杂json对象中的数据

将pyspark.sql.Rowtype数据转换为Json字符串,消除Azure Databricks NB中的值

nlohmann json:为什么我会得到一个解析错误?

条件性构建/修改嵌套对象数组

如何在 terraform 输出中打印一组用户信息

使用 jq 将消息转换为数组

Golang 解组行为:字段过多?

使用带有逗号的字段名称构建 struct

在 Perl Mojolicious 中呈现 JSON 时防止转义字符

如何判断 Json 对象中是否存在键并获取其值

如何使用 Newtonsoft.Json 反序列化 JSON 数组

如何使用 Kotlin + Jackson 将 JSON 反序列化为 List

在 Apache Spark 中读取多行 JSON

如果键可能不存在,则从 Python dict 读取

使用 JSON.NET 序列化/反序列化对象字典