Changeset: 8912acbdc9eb for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=8912acbdc9eb Modified Files: monetdb5/extras/jaql/Tests/All monetdb5/extras/jaql/Tests/json01.mal monetdb5/extras/jaql/json.c Branch: jacqueline Log Message:
json: do not force array or object at top level Prepare the way for jaql functions, which will get their arguments as JSON structs, and return a JSON struct as well. Since, e.g. count() will return a number, but range() an array, allow simple values to be represented in a JSON struct, since there is no technical limitation not to. diffs (71 lines): diff --git a/monetdb5/extras/jaql/Tests/All b/monetdb5/extras/jaql/Tests/All --- a/monetdb5/extras/jaql/Tests/All +++ b/monetdb5/extras/jaql/Tests/All @@ -1,4 +1,5 @@ json00 +json01 expand00 filter00 diff --git a/monetdb5/extras/jaql/Tests/json01.mal b/monetdb5/extras/jaql/Tests/json01.mal new file mode 100644 --- /dev/null +++ b/monetdb5/extras/jaql/Tests/json01.mal @@ -0,0 +1,17 @@ +# test non-array like strings + +s := io.stdout(); + +(j1,j2,j3,j4,j5,j6,j7) := json.shred("1"); +io.print(j1); +json.print(s, j1,j2,j3,j4,j5,j6,j7); + +(j1,j2,j3,j4,j5,j6,j7) := json.shred("null"); +io.print(j1); +json.print(s, j1,j2,j3,j4,j5,j6,j7); + +# this should be rejected +(j1,j2,j3,j4,j5,j6,j7) := json.shred("1, null"); +catch MALException:str; + io.printf("!%s\n", MALException); +exit MALException; diff --git a/monetdb5/extras/jaql/json.c b/monetdb5/extras/jaql/json.c --- a/monetdb5/extras/jaql/json.c +++ b/monetdb5/extras/jaql/json.c @@ -403,24 +403,20 @@ JSONshred(int *kind, int *string, int *i jb.error = GDKstrdup("expected data"); p = NULL; } else { - switch (*p) { - case '[': - p = parse_json_array(&jb, &v, p + 1); - break; - case '{': - p = parse_json_object(&jb, &v, p + 1); - break; - default: - jb.error = GDKstrdup("unexpected character 'X', expecting array or object"); - jb.error[22] = *p; - p = NULL; - break; - } + p = parse_json_value(&jb, &v, p); } - if (p == NULL) { - str e = createException(MAL, "json.shred", "%s", jb.error); - /* parsing failed */ + for (; p != NULL && *p != '\0' && isspace(*p); p++) + ; + if (p == NULL || *p != '\0') { + str e; + if (p == NULL) { + /* parsing failed */ + e = createException(MAL, "json.shred", "%s", jb.error); + } else { + e = createException(MAL, "json.shred", "invalid JSON data, " + "trailing characters: %s", p); + } BBPunfix(jb.kind->batCacheid); BBPunfix(jb.string->batCacheid); BBPunfix(jb.integer->batCacheid); _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list