0

I have json like

{
  "error_message_1": "missing_field_1",
  "error_message_2": "missing_field_2",
  "error_message_3": "missing_field_3"
}
I want json to be formed as below

{
"payloads":[
{
   "error_message_1": "missing_field_1",
   "error_message_2": "missing_field_2"
   "error_message_3": "missing_field_3"
}],
"timestamp":"$timestmap",
"source":"nifi"
}
   
   

please let me know the jolt script for this.

1 Answer 1

5

Use this jolt spec:

we are creating payloads array and keeping all error_message* keys into payloads array.

[{
    "operation": "shift",
    "spec": {
        "error_message_1": "payloads[0].error_message_1",
        "error_message_2": "payloads[0].error_message_2",
        "error_message_3": "payloads[0].error_message_3"
    }
}, {
    "operation": "default",
    "spec": {
      "timestamp":"$timestmap",
        "source":"nifi"
    }
}]

Output:

enter image description here

In addition if you want timestamp value for the timestamp key then use the below spec:

[{
    "operation": "shift",
    "spec": {
        "error_message_1": "payloads[0].error_message_1",
        "error_message_2": "payloads[0].error_message_2",
        "error_message_3": "payloads[0].error_message_3"
    }
}, {
    "operation": "default",
    "spec": {
      "timestamp":"${now():format('yyyy-MM-dd HH:mm:ss.SSS')}",
        "source":"nifi"
    }
}]

Output:

{
    "payloads": [{
        "error_message_1": "missing_field_1",
        "error_message_2": "missing_field_2",
        "error_message_3": "missing_field_3"
    }],
    "source": "nifi",
    "timestamp": "2018-10-30 08:51:16.572"
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.