bazaarvoice / jolt

JSON to JSON transformation library written in Java.
Apache License 2.0
1.56k stars 329 forks source link

JSON Transformation : want help to fetch array list from 3 level down with proper mapping #1179

Open ketulpatel03 opened 1 year ago

ketulpatel03 commented 1 year ago

Input : { "Report": { "level 10": { "class 1": { "Message": "demo message", "Details": { "Detail 1": { "IDENTIFICATION": { "PAN": [ "1" ] } }, "Detail 2": { "IDENTIFICATION": { "PAN": [ "2", "3" ] } }, "Detail 3": { "IDENTIFICATION": { "PAN": [ "4" ] } } } }, "class 2": { "Message": "Demo message", "Details": { "Detail 1": { "IDENTIFICATION": { "PAN": [ "5" ] } }, "Detail 2": { "IDENTIFICATION": { "PAN": [ "6", "7" ] } }, "Detail 3": { "IDENTIFICATION": { "PAN": [ "8" ] } } } } } } }

Expected Output : { "Report": { "level 10 PAN": [ { "class index": "class 1", "detail index": "detail 1", "PAN": "1" }, { "class index": "class 1", "detail index": "detail 2", "PAN": "2" }, { "class index": "class 1", "detail index": "detail 2", "PAN": "3" }, { "class index": "class 1", "detail index": "detail 3", "PAN": "4" }, { "class index": "class 2", "detail index": "detail 1", "PAN": "5" }, { "class index": "class 2", "detail index": "detail 2", "PAN": "6" }, { "class index": "class 2", "detail index": "detail 2", "PAN": "7" }, { "class index": "class 2", "detail index": "detail 3", "PAN": "8" } ] } }

mrkhedri commented 1 year ago

You can use this spec:

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "class *": {
            "*": {
              "Detail *": {
                "*": {
                  "*": { // PAN
                    "*": { // 0, 1
                      "*": {
                        "#PAN": "&9.&8 &3.&1.&1",
                        "#detail index": "&9.&8 &3.&1.detail &(5,1)",
                        "#class index": "&9.&8 &3.&1.class &(7,1)"
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": {
          "*": {
            "* *": {
              "$": "&4.&3[&2].@(1)"
            },
            "*": {
              "$": "&4.&3[&2].@(1)"
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": "=recursivelySquashNulls"
    }
  }
]