本文介绍了无法使用 Jolt 转换转换为以下格式的 json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法使用 jolt 实现上述输出格式,并且通过了多个 SO 问题,但找不到类似的问题.尝试在 jolt 规范数组中添加索引,但没有奏效.提前致谢并在下面找到输入、输出和震动规范

Unable to achieve above output format using jolt and gone through multiple SO questions and could not find similar one. Tried with adding indexes inside array of jolt spec but did not work.Thanks in Advance and find the input, output and jolt spec at below

输入:

{
  "test1": "Student",
  "School": {
    "Syllabus": {
      "Midterm": {
        "inclusions": {
          "includedSubjectsList": {
            "Subjects": [
              {
                "subjectName": "MH1"
              },
              {
                "subjectName": "MH2"
              },
              {
                "subjectName": "MH3"
              },
              {
                "subjectName": "MH4"
              }
            ]
          }
        }
      }
    }
  }
}

震动规格:

[
  {
    "operation": "shift",
    "spec": {
      "School": {
        "Syllabus": {
          "Midterm": {
            "inclusions": {
              "includedSubjectsList": {
                "Subjects": {
                  "*": {
                    "subjectName": "Academy[].books[]"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

当前输出:

{
  "Academy": [
    {
      "books": [
        "MH1"
      ]
    },
    {
      "books": [
        "MH2"
      ]
    },
    {
      "books": [
        "MH3"
      ]
    },
    {
      "books": [
        "MH4"
      ]
    }
  ]
}

预期输出:

{
  "Academy": [
    {
      "books": [
        "MH1",
        "MH2",
        "MH3",
        "MH4"
      ]
    }
  ]
}

推荐答案

你几乎是对的.替换

"subjectName": "Academy[].books[]"

"subjectName": "Academy[0].books[]"

这篇关于无法使用 Jolt 转换转换为以下格式的 json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 05:03