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

标签 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"
    },        
    {
      "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/

相关文章:

java - 如何将变量传递给 XPathExpression

php - 如何在 PHP 中使用 Horde IMAP 客户端提取电子邮件附件

php - 学习高级PHP

c++ - 在模板类中初始化 C++ 数组成员

java - 页面加载和 Selenium - 加载后驱动程序不执行任何操作

java - 获取远程文件的修改日期

java - JScrollPane 内的 JDesktopPane 调整大小问题

php - MySQL CodeIgniter 根据第一个 Select 的列从第二个表中选择或不选择

java - 原地旋转矩阵

javascript - 在 CANVAS 上绘制图像数组