gpt4 book ai didi

java - mule4/java 将 Sql ddl 模式转换为 json 模式

转载 作者:行者123 更新时间:2023-11-30 01:51:43 46 4
gpt4 key购买 nike

有从数据库检索模式,我需要将其转换为 json 模式,有人可以让我知道如何在 java 或 mule 中执行此操作。

下面是我的代码:

{"Schema": [
{
"Column_Name": "Employee Name",
"Type": "varchar",
"SafeType": "string",
"Length": 51,
"Description": null
},
{
"Column_Name": "Username",
"Type": "varchar",
"SafeType": "string",
"Length": 51
}
]}

Output should be:

{
"definitions": {},
"$schema": "http://json-schema.org/draft-07/schema#",
"$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema",
"properties": {
"Employee Name": {
"$id": "#/properties/Employee Name",
"type": "varchar",
"maxLength":50
},
"Username": {
"$id": "#/properties/Username",
"type": "string",
"maxLength":50
}
}
}

Please guide

最佳答案

%dw 2.0
output application/json

var rootObj = {
"definitions": {},
"\$schema": "http://json-schema.org/draft-07/schema#",
"\$id": "http://example.com/root.json",
"type": "object",
"title": "The Root Schema"
}

var props = payload.Schema reduce ((schema, acc={}) ->
acc ++ {
(schema.Column_Name): {
"\$id": "#/properties/$(schema.Column_Name)",
"type": schema.Type,
"maxLength": schema.Length - 1
}
})
---
rootObj ++ {"properties": props}

关于java - mule4/java 将 Sql ddl 模式转换为 json 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55762896/

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