Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generic JOLT spec for multiple input JSON #231

Closed
Kannan998 opened this issue Jul 12, 2016 · 2 comments
Closed

Generic JOLT spec for multiple input JSON #231

Kannan998 opened this issue Jul 12, 2016 · 2 comments
Labels

Comments

@Kannan998
Copy link

Kannan998 commented Jul 12, 2016

I am new to JOLT. I have 2 different set of input json of same structure except one object inside differs based on the decider value like below.

Eg: Input json 1

{
    "input": {
        "decider": 1,
        "object1": {
            "object1Info": 1,
            "obj1SpecificObj2": {
                "obj2info": "data"
            }
        },
        "doc": {
            "docId": "DOC100"
        }
    }
}

Eg: Input json 2

{
    "input": {
        "decider": 2,
        "object2": {
            "object2Info": 2,
            "obj2SpecificObj3": {
                "obj3info1": "data1",
                "obj3info2": "data2",
                "other": {
                    "otherData": "data3"
                }
            }
        },
        "doc": {
            "docId": "DOC100"
        }
    }
}

output expectation if decider : 1

{
    "out" : {
        "object" : {
            "info" : 1,
            "subObject" : {
                "subInfo" : "data"
            }
        },
        "doc": {
            "docId": "DOC100"
        }
    }
}

output expectation if decider : 2

{
    "out": {
        "object": {
            "info": 1,
            "subObject": {
                "subInfo1": "data1",
                "subInfo2": "data2",
                "other": {
                    "otherData": "data3"
                }
            }
        },
        "doc": {
            "docId": "DOC100"
        }
    }
}

I want to write a generic single conditional jolt spec which based on "decider" value output should be generated. Is there a way to write a conditional statement inside spec file....??

@milosimpson
Copy link
Contributor

Look at examples
http://jolt-demo.appspot.com/#andrewkcarter1
http://jolt-demo.appspot.com/#andrewkcarter2

In your case you need to do two shifts.

  1. to pivot the data based on the Decider
  2. then you can write a spec that has specific parts to handle each type of doc

Example Spec

[
  {
    "operation": "shift",
    "spec": {
      "input": {
        "decider": {
          "*": {
            // match down to the "value" of the decider
            // Then "grab" the whole from 3 levels up the tree
            //  and write it to the output with a path that
            //  contains the decider value
            "@3": "docType.&"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "docType": {
        "1": {
          // Do docType 1 stuff
          "input": "out"
        },
        "2": {
          // Do docType 2 stuff
          "input": "out"
        }
      }
    }
  }
]

@Kannan998
Copy link
Author

Thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants