Support Questions

Find answers, ask questions, and share your expertise

How to implement the expected output using jolt in nifi

avatar
Explorer

Hi , please help me out in achieving the expected output in Jolt

 

Input:

{
  "kind": "bresponse",
  "schema": {
    "fields": [
      {
        "name": "export_time",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "account_id",
        "type": "STRING",
        "mode": "NULLABLE"
      },
      {
        "name": "cost",
        "type": "FLOAT",
        "mode": "NULLABLE"
      }
    ]
  },
  "jobReference": {
    "projectId": "avach",
    "jobId": "job_G4hQs",
    "location": "ui"
  },
  "totalRows": "49",
  "pageToken": "BG123",
  "rows": [
    {
      "f": [
        {
          "v": "20230"
        },
        {
          "v": "0107F6-7"
        },
        {
          "v": "0.0"
        }
      ]
    },
    {
      "f": [
        {
          "v": "20230101"
        },
        {
          "v": "01DC85-B"
        },
        {
          "v": "3.48E-4"
        }
      ]
    }
  ],
  "totalBytesProcessed": "37472",
  "jobComplete": true,
  "cacheHit": false
}

 

Expected output:

 

[{
"export_time": "20230",
"account_id": "0107F6-7",
"cost": "0.0"
}, {
"export_time": "20230101",
"account_id": "01DC85-B",
"cost": "3.48E-4"
}]

1 REPLY 1

avatar
Super Guru

Hi,

 

Please try the following jolt spec:

[
  {
    "operation": "shift",
    "spec": {
      "rows": {
        "*": {
          "f": {
            "0": {
              "v": "[#4].export_time"
            },
            "1": {
              "v": "[#4].account_id"
            },
            "2": {
              "v": "[#4].cost"
            }
          }
        }
      }
    }
  }
]

If that helps please accept solution.

Thanks