gpt4 book ai didi

java - 我正在尝试为 jolt 变换创建一个 json,但我陷入了嵌套数组格式

转载 作者:行者123 更新时间:2023-11-30 01:45:25 26 4
gpt4 key购买 nike

我正在尝试转换震动,但我在嵌套数组中遇到问题。我没有得到描述值。我放了一些代码JSON 输入为

{
"id": 3,
"name": "Sample Product",
"attribute_set_id": 4,
"price" : 10,
"custom_attributes": [
{
"attribute_code": "image",
"value": "/1/_/1.jpg"
},
{
"attribute_code": "description",
"value": "<p>This is Sample Product for test</p>"
}
]
}

我的 Jolt 规范是

[
{
"operation": "shift",
"spec": {
"id": "id",
"name": "name",
"description": "custom_attributes[0].attribute_code.value"
}
]

我的预期输出是

{
"id" : 3,
"name" : "Sample Product",
"description" : "<p>This is Sample Product for test</p>",
"image" : "/1/_/1.jpg",
"start_price" : 10,
"current_price" : 10
}

最佳答案

如果 "attribute_code": "image""attribute_code": "description" 始终出现在数组的第一个和第二个元素中,您可以简单地转换给定 JSON 字符串,其 Jolt 规范如下:

[
{
"operation": "shift",
"spec": {
"id": "id",
"name": "name",
"custom_attributes": {
"1": {
"value": "description"
},
"0": {
"value": "image"
}
},
"price": ["start_price", "current_price"]
}
}
]

关于java - 我正在尝试为 jolt 变换创建一个 json,但我陷入了嵌套数组格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58214223/

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