Arun Sai
Arun Sai

Reputation: 1982

Unable to transform into below format json using Jolt transformation

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

Input:

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

Jolt Spec:

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

Current output:

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

Expected output:

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

Upvotes: 1

Views: 189

Answers (1)

kasptom
kasptom

Reputation: 2458

You are almost right. Replace

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

with

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

Upvotes: 3

Related Questions