0

I want to transform a JSON using JOLT, in the following way.:

Input of json file

{
  "Document_No": "ANG4",
  "LineNo10": {
    "Type": 1,
    "Customer_No_": "1"
  },
  "LineNo11": {
    "Type": 2,
    "Customer_No_": "2"
  },
  "LineNo12": {
    "Type": 3,
    "Customer_No_": "3"
  }
}

Desired output of json file

  [ 
    {
      "Document_No":"ANG4"  
      "Type" : 1,
      "Customer_No_" : "1",
      "Line_No" : "10"
    }, 
    {
      "Document_No":"ANG4"
      "Type" : 2,
      "Customer_No_" : "2",
      "Line_No" : "11"
    }, 
    {
      "Document_No":"ANG4"
      "Type" : 3,
      "Customer_No_" : "3",
      "Line_No" : "12"
    } 
    ]

I don't lack a lot, but i don't know what transformations add to get the desired output

my Jolt specificaton is below

[
  {
    "operation": "shift",
    "spec": {
      "LineNo*": {
        "@": "&",
        "$": "&.Line_No"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[]"
      }
    }
  }
]

My output json file :

[ {
  "Type" : 1,
  "Customer_No_" : "1",
  "Line_No" : "LineNo10"
}, {
  "Type" : 2,
  "Customer_No_" : "2",
  "Line_No" : "LineNo11"
}, {
  "Type" : 3,
  "Customer_No_" : "3",
  "Line_No" : "LineNo12"
} ]

Could anyone help me with this?

tomar
  • 83
  • 1
  • 1
  • 7

1 Answers1

0

Spec

[
  {
    "operation": "shift",
    "spec": {
      "LineNo*": {
        // copy Document_No down into the "LineNo" maps
        "@(1,Document_No)": "&1.Document_No",
        "$": "&1.Line_No",
        "*": "&1.&"
      }
    }
  },
  {
    // accumulate all the "built" LineNo's into an array
    "operation": "shift",
    "spec": {
      "*": {
        "@": "[]"
      }
    }
  }
]
Milo S
  • 4,466
  • 1
  • 19
  • 22