0

I'm a new in JOLT and need a help in a transformation.

Case is - adding key:value to the top of plain JSON, shifting other pairs down to bottom.

Initial json

{ "keyA":"valueA",
  "keyB":"valueB"}

Jolt Specification

[{"operation": "default",
  "spec": {
    "metaA": "metaValueA",
    "metaB": "metaValueB"
}}]

Desired output

{   "metaA": "metaValueA",
    "metaB": "metaValueB",
    "keyA": "valueA",
    "keyB": "valueB"}

Real output

{   "keyA": "valueA",
    "keyB": "valueB",
    "metaA": "metaValueA",
    "metaB": "metaValueB"}

Similar example gives not similar json in this case.

Thank all for your help!

romBasic
  • 3
  • 2

1 Answers1

1

Although JSON objects are unordered by definition.

It can be achieved by running a simple shift to change order:

[{
    "operation": "default",
    "spec": {
      "metaA": "metaValueA",
      "metaB": "metaValueB"
    }
},
  {
    "operation": "shift",
    "spec": {
      "keyA": "&",
      "keyB": "&",
      "metaA": "&",
      "metaB": "&"
    }
 }]
Community
  • 1
  • 1
Matthew Warman
  • 3,234
  • 2
  • 23
  • 35