2

I am trying to do JOLT shift operation with below spec which is not working. Not sure what mistake I have done. Need help in this case. Output JSON is coming as an object instead of Array and shift also not working as expected.

    Input : [
      {
        "Header": {
          "Number": 1,
          "Id": "JO"
        },
        "Name": "John"
      },
      {
        "Header": {
          "Number": 2,
          "Id": "JS"
        },
        "Name": "Justin"
      }
    ]
    Spec : [
      {
        "operation": "shift",
        "spec": {
          "*": {
            "Header": "Header",
            "Name": "Header.Name"
          }
        }
      }
    ]
    Expected Output : [
      {
        "Header": {
          "Number": 1,
          "Id": "JO",
          "Name": "John"
        }    
      },
      {
        "Header": {
          "Number": 2,
          "Id": "JS",
          "Name": "Justin"
        }    
      }
    ]
    Actual Output : {
      "Header" : [ {
        "Number" : 1,
        "Id" : "JO",
        "Name" : "John"
      }, {
        "Number" : 2,
        "Id" : "JS"
      } ]
    }

1 Answer 1

2

You have to also specify that the "Header" object is inside the array.

Moreover, the index of the array where you place the "Header" object for each of the element of the array.

That's what the spec below does (using the [&1] - apmersand wildcard combined with array):

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "Header": "[&1].Header",
        "Name": "[&1].Header.Name"
      }
    }
  }
]

Sources:

  1. Shiftr.java javadocs:
  2. Other answer: "How do I transform an array using Jolt?"
  3. Demo application linked in the jolt repo to test the spec
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, @kasptom. It's working. You helped me on 3 issues till now related to JOLT.
any good source to read the documentation of jolt? this is very obscure until now...#
@ΦXocę웃Пepeúpaツ I've edited the answer and added the best sources I know of.

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.