Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ordering of json objects after jolt transformation

Tags:

json

jolt

Input:

{

//The input json object

}

Desired Output:

{

"Event1": "Value1",
"Event2": [
            // collection of json objects
          ],

"Event3": {
            //The input json object
          }

}

So basically the input json goes in the "Event3" of another json object wrapper.

This is my Spec:

[
  {
    "operation": "shift",
    "spec": {
      "@": "Event3"
    }
  },
  {
    "operation": "default",
    "spec": {
      "Event1": "Value1",
      "Event2": [
        // some objects
       ]
    }
  }
]

Now the problem is - the above spec is doing the transformation, but ordering of the objects are messed up, like this:

{
"Event3": {
            //The input json object
          },
          
"Event2": [
            // some objects
          ],
"Event1": "Value1"

}

Please suggest how should I fix this.

like image 915
Ray Avatar asked Sep 03 '25 10:09

Ray


1 Answers

have you tried using the sort operation?

[
  {
    "operation": "sort",
    "spec": {
      "*": ""
    }
  }
]

Think that might do the trick for you ;)

like image 169
Lemmerich Avatar answered Sep 05 '25 02:09

Lemmerich