gpt4 book ai didi

在 esql 中创建 JSON 数组

转载 作者:行者123 更新时间:2023-12-05 03:02:17 31 4
gpt4 key购买 nike

我是 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}
}

最佳答案

这就是创建 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;

关于在 esql 中创建 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55025495/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com