0

Input:

{
"k1": "v1",
"k2": "v2",
"event": "SUMMARY"
}

Expected output:

{
  "k1": "v1",
  "k2": "v2",
  "event": "SUMMARY",
  "arr": [
    {
      "k1": "v1",
      "key": "first"
    },
    {
      "k2": "v2",
      "key": "second"
    },
    {
      "summary1": "s1",
      "key": "SUMMARY"
    },
    {
      "summary1": "s2",
      "key": "SUMMARY"
    }
  ]
}

For each 'k1' and 'k2', respective array element should be added as

{
"k2": "v2",
"key": "second"
}

For when event = "SUMMARY", respective 2 elements should be added as

{
"summary1": "s1",
"key": "SUMMARY"
},
{
"summary2": "s2",
"key": "SUMMARY"
}

Please help with JOLT specification

1 Answer 1

1

Since you gave input and output based on that i written one function in javascript.

{ "k1": "v1", "k2": "v2", "event": "SUMMARY" }

Well that function will work only for above input

and also you have to mention that whether u want output in which language...

//Input

var obj = {
    "k1": "v1",
    "k2": "v2",
    "event": "SUMMARY"
}

//funciton calling 
obj["arr"] = checkThis(obj);



//output
console.log(obj)




function checkThis(obj) {
    var arr = [];
    Object.keys(obj)
        .forEach(function eachKey(key) {
            if (key == "k1") {
                var tempObj = {}
                tempObj["k1"] = obj[key];
                tempObj["key"] = "first";
                arr.push(tempObj)
            } else if (key == "k2") {
                var tempObj = {}
                tempObj["k2"] = obj[key];
                tempObj["key"] = "second";
                arr.push(tempObj)
            } else if (key == "event") {
                var tempObj1 = {}
                var tempObj2 = {}
                tempObj1["summary1"] = "s1";
                tempObj1["key"] = obj[key];
                tempObj2["summary1"] = "s2";
                tempObj2["key"] = obj[key];
                arr.push(tempObj1)
                arr.push(tempObj2)
            }
        });                        
return arr;
}

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

1 Comment

Thanks for trying out, but as mentioned in question title, i require JOLT specification to process this not javascript code. For JOLT reference refer: github.com/bazaarvoice/jolt

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.