Support Questions

Find answers, ask questions, and share your expertise

Jolt transform for moving json message to subset without mapping all the fields one by one

avatar

I'm to Jolt transformation. I have a simple requirement to transform a json message, were I have to move the contents of the message to a subset without mapping the filed one by one. Input message: { "primary": { "value": 4 }, "quality": { "value": 3 } } Expected Output: { Data:{ "primary": { "value": 4 }, "quality": { "value": 3 } } }.,HI, I am looking to convert a json message using Jolt. it is a simple transformation, were i have to move the entire json message to a subset without mapping field by field

@Matt Burgess

1 ACCEPTED SOLUTION

avatar
Master Guru
@Saravanan Subramanian

Try with below Jolt Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": "Data.&"
    }
  },
  {
    "operation": "default",
    "spec": {
      "Data": {}
    }
  }
]


Input:

{
  "primary": {
    "value": 4
  },
  "quality": {
    "value": 3
  }
}

Output:

{
  "Data" : {
    "primary" : {
      "value" : 4
    },
    "quality" : {
      "value" : 3
    }
  }
}

86580-jolt.png

Another way of doing this is using Replace Text processor by capturing all the content of flowfile and replacement value as

Search Value

(^.*$)

Replacement Value

{ "Data": $1 }

Character Set

UTF-8

Maximum Buffer Size

1 MB

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

View solution in original post

2 REPLIES 2

avatar
Master Guru
@Saravanan Subramanian

Try with below Jolt Spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": "Data.&"
    }
  },
  {
    "operation": "default",
    "spec": {
      "Data": {}
    }
  }
]


Input:

{
  "primary": {
    "value": 4
  },
  "quality": {
    "value": 3
  }
}

Output:

{
  "Data" : {
    "primary" : {
      "value" : 4
    },
    "quality" : {
      "value" : 3
    }
  }
}

86580-jolt.png

Another way of doing this is using Replace Text processor by capturing all the content of flowfile and replacement value as

Search Value

(^.*$)

Replacement Value

{ "Data": $1 }

Character Set

UTF-8

Maximum Buffer Size

1 MB

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

-

If the Answer helped to resolve your issue, Click on Accept button below to accept the answer, That would be great help to Community users to find solution quickly for these kind of issues.

avatar

Thanks very much @Shu for your solution . I managed to find a way which is almost similar to yours.