More JSON-y struct string representation

This commit is contained in:
Sage Vaillancourt 2023-12-22 14:31:06 -05:00
parent 8120889bfd
commit e97746ce07
2 changed files with 7 additions and 2 deletions

View File

@ -191,7 +191,12 @@ void stringStruct(struct string* s, const Object* obj)
struct StructDef* def = getStructAt(so->definition);
for (int i = 0; i < def->fieldCount; i++) {
appendf(s, " %s: ", def->names[i]);
appendf(s, " \"%s\": ", def->names[i]);
if (so->fields[i].type == TYPE_SYMBOL && so->fields[i].string == NULL) {
appendf(s, "null,");
continue;
}
int isString = so->fields[i].type == TYPE_STRING;
if (isString) {
appendf(s, "\"");

View File

@ -206,7 +206,7 @@ title "Structs"
check "Struct Definition" "(struct Post (title body))" "T"
check "Building a struct"\
'(struct Post (title body)) (Post "A title" "The Body")'\
'{ title: "A title", body: "The Body" }'
'{ "title": "A title", "body": "The Body" }'
check "Accessing struct fields"\
"(struct Post (title body)) (def p (Post \"TITLE\" \"BODY\")) (p.title p.body)"\
"( TITLE BODY )"