How do I use Jolt to flatten a json array of n objects?

5k views Asked by At

Just starting out with Jolt and I'm trying to transform the following input:

{
    "task_name": "Data Full Load",
    "table": "enterprise",
    "schema": "dbo",
    "op": "F",
    "data": [
        {
            "enterprise_id": "00001"
        },
        {
            "enterprise_name": "FOO"
        },
        {
            "note": ""
        },
        {
            "delete_ind": "N"
        },
        {
            "create_timestamp": "2004-11-03 22:28:08.180"
        },
        {
            "modify_timestamp": "2016-05-02 13:02:53.437"
        },
        {
            "row_timestamp": "0x000000001CDCAAC3"
        }
    ]
}

Into this output:

{
    "enterprise_id": "00001",
    "enterprise_name": "FOO",
    "note": "",
    "delete_ind": "N",
    "create_timestamp": "2004-11-03 22:28:08.180",
    "modify_timestamp": "2016-05-02 13:02:53.437",
    "row_timestamp": "0x000000001CDCAAC3"
}

My data will have various unknown elements, so I can't transform them by name. I'm able to use this spec to extract the data array, but I'm not sure how to combine the elements

[
  {
    "operation": "shift",
    "spec": { "data": "" }
}
]

current output:

[ {
  "enterprise_id" : "00001"
}, {
  "enterprise_name" : "FOO"
}, {
  "note" : ""
}, {
  "delete_ind" : "N"
}, {
  "create_timestamp" : "2004-11-03 22:28:08.180"
}, {
  "modify_timestamp" : "2016-05-02 13:02:53.437"
}, {
  "row_timestamp" : "0x000000001CDCAAC3"
} ]
1

There are 1 answers

1
DataG On

After a little wrangling on jolt-demo.appspot.com I figured it out. For those that are encountering the same challenge, here is the spec:

[
  {
    "operation": "shift",
    "spec": {
      "data": {
        "*": {
          "*": "&0"
        }
      }
    }
}
]