颠簸转换后的json对象排序

时间:2019-09-30 16:12:19

标签: json jolt

输入:

{

//The input json object

}

所需的输出

{

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

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

}

所以基本上,输入的json放在另一个json对象包装的“ Event3”中。

这是我的规范:

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

现在的问题是-上面的规范正在执行转换,但是对象的顺序混乱了,像这样:

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

"Event2": [
            // some objects
          ],
"Event1": "Value1"

}

请建议我该如何解决。

3 个答案:

答案 0 :(得分:0)

您是否尝试过使用排序操作?

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

认为这可能对您有用;)

答案 1 :(得分:0)

尝试最后使用另一个shift操作以使它们按所需的顺序显示。

[
  {
    "operation": "shift",
    "spec": {
      "@": "Event3"
    }
    },
  {
    "operation": "default",
    "spec": {
      "Event1": "Value1",
      "Event2": [
        "ob1", "obj2"
        ]
    }
    },
  {
    "operation": "shift",
    "spec": {
      "Event1": "Event1",
      "Event2": "Event2",
      "Event3": "Event3"
    }
    }
]

答案 2 :(得分:0)

添加另一个移位操作,只需将输入json中的每个字段复制粘贴到输出json。

[
  {
    "operation": "shift",
    "spec": {
      "@": "Event3"
    }
    },
  {
    "operation": "default",
    "spec": {
      "Event1": "Value1",
      "Event2": [
        "ob1", "obj2"
        ]
    }
    },
  {
    "operation": "shift",
    "spec": {
      "Event1": "&", //same as "Event1":"Event1",
      "Event2": "&",
      "Event3": "&"
    }
    }
]