diff --git a/modules/database/src/ioc/dbStatic/dbYacc.y b/modules/database/src/ioc/dbStatic/dbYacc.y index 80b031fac..cc563bcfd 100644 --- a/modules/database/src/ioc/dbStatic/dbYacc.y +++ b/modules/database/src/ioc/dbStatic/dbYacc.y @@ -32,8 +32,8 @@ static int yyAbort = 0; %token jsonNULL jsonTRUE jsonFALSE %token jsonNUMBER jsonSTRING jsonBARE -%type json_value json_object json_array -%type json_members json_pair json_elements json_string +%type json_value json_string json_object json_array +%type json_members json_pair json_key json_elements %% @@ -299,13 +299,24 @@ json_members: json_pair if (dbStaticDebug>2) printf("json %s\n", $$); }; -json_pair: json_string ':' json_value +json_pair: json_key ':' json_value { $$ = dbmfStrcat3($1, ":", $3); dbmfFree($1); dbmfFree($3); if (dbStaticDebug>2) printf("json %s\n", $$); }; +json_key: jsonSTRING + | jsonBARE +{ + /* A key containing any of these characters must be quoted for YAJL */ + if (strcspn($1, "+-.") < strlen($1)) { + $$ = dbmfStrcat3("\"", $1, "\""); + dbmfFree($1); + } + if (dbStaticDebug>2) printf("json %s\n", $$); +}; + json_string: jsonSTRING | jsonBARE { diff --git a/modules/database/test/ioc/db/dbPutLinkTest.c b/modules/database/test/ioc/db/dbPutLinkTest.c index 5158e3c91..830d37f6c 100644 --- a/modules/database/test/ioc/db/dbPutLinkTest.c +++ b/modules/database/test/ioc/db/dbPutLinkTest.c @@ -255,7 +255,7 @@ typedef struct { } testHWDataT; static const testHWDataT testHWData[] = { - {"rJSON_LINK", JSON_LINK, "{\"x\":true}", {0}, "{\"x\":true}"}, + {"rJSON_LINK", JSON_LINK, "{x:true}", {0}, "{x:true}"}, {"rVME_IO", VME_IO, "#C100 S101 @parm VME_IO", {100, 101}, "parm VME_IO"}, {"rCAMAC_IO", CAMAC_IO, "#B11 C12 N13 A14 F15 @parm CAMAC_IO", {11, 12, 13, 14, 15}, "parm CAMAC_IO"}, {"rAB_IO", AB_IO, "#L21 A22 C23 S24 @parm AB_IO", {21, 22, 23, 24}, "parm AB_IO"}, @@ -585,7 +585,7 @@ void testJLink(void) testdbPutFieldOk("j2.PROC", DBF_LONG, 1); testdbPutFieldOk("j3.PROC", DBF_LONG, 1); - testdbGetFieldEqual("j1.INP", DBF_STRING, "{\"z\":{\"good\":1}}"); + testdbGetFieldEqual("j1.INP", DBF_STRING, "{z:{good:1}}"); testdbGetFieldEqual("j1.VAL", DBF_LONG, 1); testdbGetFieldEqual("j2.VAL", DBF_LONG, 2); testdbGetFieldEqual("j3.VAL", DBF_LONG, 3); diff --git a/modules/database/test/ioc/db/dbStaticTest.db b/modules/database/test/ioc/db/dbStaticTest.db index 75e981f1a..bc25d1a23 100644 --- a/modules/database/test/ioc/db/dbStaticTest.db +++ b/modules/database/test/ioc/db/dbStaticTest.db @@ -81,4 +81,7 @@ record(x, "t1") { field(F64, -Infinity) field(F32, Nan) field(F64, Nan) + + info(i1, {x:0, +x:1, -x:2, .x:3}) + info(i2, Bare-word_string) } diff --git a/modules/database/test/std/rec/linkRetargetLinkTest.c b/modules/database/test/std/rec/linkRetargetLinkTest.c index bf98bc1f9..dab000167 100644 --- a/modules/database/test/std/rec/linkRetargetLinkTest.c +++ b/modules/database/test/std/rec/linkRetargetLinkTest.c @@ -75,18 +75,18 @@ static void testRetargetJLink(void) testdbGetFieldEqual("rec:j1", DBF_DOUBLE, 10.0); /* minimal args */ - testLongStrEq("rec:j1.INP$", "{\"calc\":{\"expr\":\"A+5\",\"args\":5}}"); + testLongStrEq("rec:j1.INP$", "{calc:{expr:\"A+5\",args:5}}"); /* with [] */ testPutLongStr("rec:j1.INP$", "{\"calc\":{\"expr\":\"A+5\",\"args\":[7]}}"); testdbPutFieldOk("rec:j1.PROC", DBF_LONG, 1); /* with const */ - testPutLongStr("rec:j1.INP$", "{\"calc\":{\"expr\":\"A+5\",\"args\":[{\"const\":7}]}}"); + testPutLongStr("rec:j1.INP$", "{calc:{expr:\"A+5\",args:[{const:7}]}}"); testdbPutFieldOk("rec:j1.PROC", DBF_LONG, 1); testdbGetFieldEqual("rec:j1", DBF_DOUBLE, 12.0); - testLongStrEq("rec:j1.INP$", "{\"calc\":{\"expr\":\"A+5\",\"args\":[{\"const\":7}]}}"); + testLongStrEq("rec:j1.INP$", "{calc:{expr:\"A+5\",args:[{const:7}]}}"); } MAIN(linkRetargetLinkTest)