Also ich versuche, das Format der JSON von einer API zurückgegeben, ich schreibe gegen und ich würde gerne wissen, ob es ein beliebiges Format für die Dokumentation der JSON-Struktur gibt.Syntax für die Dokumentation der JSON-Struktur
Hinweis Ich versuche nicht, etwas zu testen oder zu validieren, ich benutze es nur zur Dokumentation. Es gibt auch einige Möglichkeiten, Kommentare zu Nicht-Konstanten hinzuzufügen (Elemente, die immer mit demselben Wert zurückgegeben werden).
Dies ist die nicht ganz durchdacht Schema ich zur Zeit mit:
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.
Beispiel:
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
}
Ich denke, Ihr Schema ist eigentlich ein ziemlich guter Ausgangspunkt. Ich würde vorschlagen, für Felder, die begrenzte Werte haben, Syntax wie '" Modus "zu verwenden:" schnell "| "mittel" | "slow", ', wobei jeder mögliche Wert explizit als Literal-String oder int oder boolean angegeben wird. Der vertikale Balken '|' ist in JSON (außerhalb einer Zeichenkette) nicht zulässig, daher wird seine Bedeutung als Meta-Zeichen verstanden. –