我是IIB的新手,我正在努力在扩展SQL中创建以下JSON数据。请建议我。
{
"name" : "John Doe",
"age" : -1,
"known" : false,
"address" : { "street" : null, "city" : "unknown" },
"belongings" : ["this", "that", "the other"]
}
我的ESQL代码:
DECLARE vm ROW;
SET vm.Name[] = LIST{13,08,25,06};
SET OutputRoot.JSON.Data.name = 'John Doe';
SET OutputRoot.JSON.Data.age = 1;
SET OutputRoot.JSON.Data.known = false;
SET OutputRoot.JSON.Data.address.street = null;
SET OutputRoot.JSON.Data.address.city = 'Unknown';
SET OutputRoot.JSON.Data.belongings = vm;
输出:
{
"name":"John Doe",
"age":1,
"known":false,
"address":{"city":"Unknown"},
"belongings":{"Name":13,"Name":8,"Name":25,"Name":6}
}
答案 0 :(得分:0)
这就是创建JSON数组的方式:
CREATE FIELD OutputRoot.JSON.Data.belongings IDENTITY(JSON.Array)belongings;
SET OutputRoot.JSON.Data.belongings.Item[1]=13;
SET OutputRoot.JSON.Data.belongings.Item[2]=8;
SET OutputRoot.JSON.Data.belongings.Item[3]=25;
SET OutputRoot.JSON.Data.belongings.Item[4]=6;