【问题标题】:Transform list array inside an array in json在json中的数组内转换列表数组
【发布时间】:2019-10-09 17:16:02
【问题描述】:

我是 JOLT 转型的新手。我正在尝试创建一个转换规范。 我在对象中有一个类别列表,我只需要转换一些细节。

我的示例代码和规范如下所示。

在“0/SYS_CATALOG_DESCRIPTION”列表中,我需要将其转换为基于语言的字符串,即对于 en_US,我需要获取 AA 产品 最终结果将是“_description”:“AA 产品”

“子类别”应该给我以下结果:

"subCategories": [
{
"_id": "ce_155584",
"_parentIds": ["ce_128375"],
"_description": "Filters" //based on lang = en_US
}
]

示例 JSON:

{
  "total": 16,
  "max_score": 2.2809339,
  "hits": [
    {
      "_index": "bosch-dms-frontend-service_en_us_1558584002",
      "_type": "categories",
      "_id": "ce_128375",
      "_score": 2.2809339,
      "_source": {
        "_parentIds": [
          "1234"
        ],
        "0/SYS_CATALOG_DESCRIPTION": [
          {
            "lang": "de_DE",
            "value": "AA Produkte"
          },
          {
            "lang": "en_US",
            "value": "AA Products"
          }
        ],
        "subCategories": [
          {
            "_index": "bosch-dms-frontend-service_en_us_1558584002",
            "_type": "categories",
            "_id": "ce_155584",
            "_score": 2.2809339,
            "_source": {
              "_parentIds": [
                "ce_128375"
              ],
              "0/SYS_CATALOG_DESCRIPTION": [
                {
                  "lang": "en_US",
                  "value": "Filters"
                },
                {
                  "lang": "zh_CN",
                  "value": "AA Filters (CN)"
                }
              ],
              "0/SYS_SYSTEMNAME": "AA_Filters"
            }
          }
        ]
      }
    }
  ]
}

规格:

[

  {
    "operation": "shift", // shift operation
    "spec": {
      "hits": {
        "*": { 
          "_id": "_id",
          "_source": {
            "_parentIds": "_parentIds",
            "0/SYS_CATALOG_DESCRIPTION": "_description",
          }
        }
      }
    }
    }

]

最终结果将是

{
  "_id" : "ce_128375",
  "_parentIds" : [ "1234" ],
  "_description" : "AA Products (BR)",
   "subCategories": [ 
            {
            "_id": "ce_155584",
            "_score": 2.2809339,
            "_parentIds": ["ce_128375"],
            "_description" : "Filters"
            }

   ]
}

我尝试了几种方法,但都没有达到效果。 谢谢。

【问题讨论】:

    标签: jolt


    【解决方案1】:

    检查此规范是否是您所需要的:

    [
    
      {
        "operation": "shift", // shift operation
        "spec": {
          "hits": {
            "*": {
              "_id": ["&",
                              "subCategories.[]._parentIds[]"],
              "_source": {
                "_parentIds": "&",
                "0/SYS_CATALOG_DESCRIPTION": {
                  "*": {
                    "lang": {
                      "en_US": {
                        "@(2,value)": "_description"
                      }
                    }
                  }
                },
                "subCategories": {
                  "*": {
                    "_id": "subCategories.[&1].&",
                    "_score": "subCategories.[&1].&",
                    "_source": {
                      "0/SYS_CATALOG_DESCRIPTION": {
                        "*": {
                          "lang": {
                            "en_US": {
                              "@(2,value)": "subCategories.[&6]._description"
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
        }
    
    ]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-22
      • 1970-01-01
      • 2022-09-24
      • 2020-08-08
      • 2020-04-27
      • 2012-06-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多