0

Input JSON :

{

  "type": "mbrInfo",
  "csId": 123456789,
  "insTS": "14-07-201911:55",
  "seqId": 1234565,
  "title": "Mr",
  "fName": "Amit",
  "mName": "",
  "lName": "V",
  "suffix": "Engg",
  "lvlId": "P",
  "lvlType": "LAC",
  "acctStatus": "20",
  "enrlDT": "2016-08-29",
  "vrsnId": 1
}

Expected Output JSON:

{

  "type": "mbrInfo",
  "csId": 123456789,
  "insTS": "14-07-201911:55",
  "seqId": 1234565,
   "name" : [{
  "title": "Mr",
  "fName": "Amit",
  "mName": "",
  "lName": "V",
  "suffix": "Engg"}],
  "lvlId": "P",
  "lvlType": "LAC",
  "acctStatus": "20",
  "enrlDT": "2016-08-29",
  "vrsnId": 1
}.

Currently I am using JOLTtransformJSON processor with JOLT Spec as :

[
{
    "operation": "shift",
    "spec": {
      "name": {
        "$": "[#1]",
        "@.title": "[#1].title",
        "@.fName": "[#1].fName",
        "@.mName": "[#1].mName",
        "@.lName": "[#1].lName",
        "@.suffix": "[#1].suffix"
      }
    }
  }
]

But all I am getting is either NULL or the original JSON (with diff spec) as output. Thanks in advance.

1
  • Oscar , if you look carefully you will find the input json to be a flat json whereas the output one is nested. Commented Aug 23, 2019 at 10:40

1 Answer 1

1

Is the intent to put all the name fields into a 1-element array containing an object. This JOLT spec puts them into an object at the name field:

[
  {
    "operation": "shift",
    "spec": {
      "title": "name.title",
      "fName": "name.fName",
      "mName": "name.mName",
      "lName": "name.lName",
      "suffix": "name.suffix",
      "*": "&"
    }
  }
]

...and this spec puts them into a 1-element array at the name field:

[
  {
    "operation": "shift",
    "spec": {
      "title": "name[0].title",
      "fName": "name[0].fName",
      "mName": "name[0].mName",
      "lName": "name[0].lName",
      "suffix": "name[0].suffix",
      "*": "&"
    }
  }
]

I don't see any other place in the input to get an index into the array, so I just used 0.

Sign up to request clarification or add additional context in comments.

1 Comment

@mattyb , please can you help me with this question stackoverflow.com/questions/57693401/…

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.