Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
240 views
in Technique[技术] by (71.8m points)

JOLT Merging dissimilar elements

Here is my input

 [{
    "name": "LAST_UPDATE_DATE",
    "value": 1075456461000
  },
  {
    "name": "LAST_UPDATED_BY",
    "value": {
      "value": "BCw="
    }
  }]

Here is the expected output

 [{
    "name": "LAST_UPDATE_DATE",
    "value": 1075456461000
  },
  {
    "name": "LAST_UPDATED_BY",
    "value":  "BCw="
    
  }]

Tried to add default fields so that I can compare further, but can't seem to create a node with a value already existing ( value: 1075456461000 )

    [{
    "operation": "modify-default-beta",
    "spec": {
        "*": {
          "val" : null,
          "value": {
            "val" : null
          }
        }
      }
  }]

Any suggestions are appreciated.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

After several hours of struggle here is what I came up with ....

    [
 {
        "operation": "shift",
        "spec": {
          "*": {
            "$": "&1.fieldname",
            "@": "&1.val",
            "value": "&1.value"
          }
        }
      },
      {
        "operation": "remove",
        "spec": {
          "*": {
            "*": {
              "value": ""
            }
          }
        }
      },
      {
        "operation": "default",
        "spec": {
          "*": {
            "value": null
          }
        }
      },
      {
        "operation": "modify-default-beta",
        "spec": {
          "*": {
            "value?": "@(1,val)"
          }
        }
      },
      {
        "operation": "remove",
        "spec": {
          "*": {
            "val": ""
          }
        }
      }
    ]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...