Better json management

This commit is contained in:
2024-02-21 13:49:13 -03:00
parent f9dedca988
commit 9c5eb45d95
4 changed files with 48 additions and 42 deletions

View File

@@ -9,10 +9,13 @@ import util;
* https://www.w3.org/TR/activitypub/#obj
+/
class ASObject {
// Required fields (for root objects)
string context; /// Must be activitystream context
string id; /// AP requirement for unique identifier
string type; /// AP requirement for type of object
// Optional fields
JSONValue raw;
/++
@@ -25,24 +28,23 @@ class ASObject {
with (this) {
const(JSONValue)* ascontext = "@context" in json;
if (ascontext == null)
throw new Exception("No context in ActivityStream Object");
if (ascontext) {
switch ((*ascontext).type) {
case JSONType.ARRAY:
context = (*ascontext)[0].str;
break;
switch ((*ascontext).type) {
case JSONType.ARRAY:
context = (*ascontext)[0].str;
break;
case JSONType.STRING:
context = (*ascontext).str;
break;
case JSONType.STRING:
context = (*ascontext).str;
break;
default:
throw new Exception("Invalid @context type for ActivityStream Object");
default:
throw new Exception("Invalid @context type for ActivityStream Object");
}
}
id = json.requiredKey!"id".str;
type = json.requiredKey!"type".str;
optional(json, "id", id);
optional(json, "type", type);
raw = json;
}