Java 我试图为jolt转换生成一个json,但我被困在嵌套数组格式中
我正在尝试转换震动,但在嵌套数组中遇到了问题。我没有得到描述值。 我放了一些密码 JSON输入是Java 我试图为jolt转换生成一个json,但我被困在嵌套数组格式中,java,php,arrays,jolt,Java,Php,Arrays,Jolt,我正在尝试转换震动,但在嵌套数组中遇到了问题。我没有得到描述值。 我放了一些密码 JSON输入是 { "id": 3, "name": "Sample Product", "attribute_set_id": 4, "price" : 10, "custom_attributes": [ { "attribute_code": "image", "value": "/1/_/1.jpg" }, {
{
"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>"
}
]
}
我的预期产出是
{
"id" : 3,
"name" : "Sample Product",
"description" : "<p>This is Sample Product for test</p>",
"image" : "/1/_/1.jpg",
"start_price" : 10,
"current_price" : 10
}
{
“id”:3,
“名称”:“样品产品”,
“说明”:“这是用于测试的样品产品”,
“图像”:“/1/wu/1.jpg”,
“起始价格”:10,
“当前价格”:10
}
如果“attribute\u code”:“image”
和“attribute\u code”:“description”
总是出现在数组的第一个和第二个元素中,您可以简单地使用以下Jolt规范转换给定的JSON字符串:
[
{
"operation": "shift",
"spec": {
"id": "id",
"name": "name",
"custom_attributes": {
"1": {
"value": "description"
},
"0": {
"value": "image"
}
},
"price": ["start_price", "current_price"]
}
}
]
但是我对像“custom_attributes”这样的图像执行相同的代码:{“1”:{“value”:“Image”}}它会抛出错误:duplicatekey@Krunal潘迪亚,我试过了,没问题!您只需将密钥从description重命名为image。没人,我想要这两个属性,在我的实际代码中,有超过15个自定义_属性,我想要其中5个。@Krunal Pandya我已经更新了我的帖子。如果您想检索数组中具有特定索引的更多元素,可以展开它。我有价格值,必须将其添加到差异变量中。我编辑我的问题,请查看它。
[
{
"operation": "shift",
"spec": {
"id": "id",
"name": "name",
"custom_attributes": {
"1": {
"value": "description"
},
"0": {
"value": "image"
}
},
"price": ["start_price", "current_price"]
}
}
]