Home > Mobile >  jolt transformation of this complex scenario?
jolt transformation of this complex scenario?

Time:11-11

I want the jolt transform for the given input . Your help in this is highly appreciated . thanks i am providing the input and expected output. in input json Photos array is dynamic in nature. Here it is 3 , it can be 3 or 4 or5 any .

Input JSON :

{
  "Entity": {
    "card": {
     "cardNo":"123456789",
      "cardStatus":"10",
      "cardAddress":"UK",
      "cardAddress1":"US",
      "cardCity":"mk" ,
       "name": "RAM",
      "lastName": "ABU",
       "name1": "RAM1",
      "lastName1": "ABU1"
    },
    "Photos": [
      {
        "Id": 327703,
        "Caption": "TEST>> photo 1",
        "Url": "http://bob.com/0001/327703/photo.jpg"
      },
      {
        "Id": 327704,
        "Caption": "TEST>> photo 2",
        "Url": "http://bob.com/0001/327704/photo.jpg"
      },
      {
        "Id": 327704,
        "Caption": "TEST>> photo 2",
        "Url": "http://bob.com/0001/327704/photo.jpg"
      }
    ]
  }
}

Used Jolt Spec :

[
  {
    "operation": "shift",
    "spec": {
      "Entity": {
        "card": {
          "cardNo": "tab.text",
          "cardAddress": "address[0].add",
          "cardAddress1": "address[0].add2",
          "cardC*": "address[0].mk",
          "Id1": "Photos.no",
          "#http.1.com": "Photos.caption2",
          "Id2": "Photos.no",
          "#http.2.com": "Photos.caption2"
        },
        "Photos": {
          "*": {
            "Id": "Photos.no",
            "Caption": "Photos.caption2"
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "tab": "&",
      "address": "&",
      "Photos": {
        "*": {
          "*": {
            "@": "&3[&1].&2"
          }
        }
      }
    }
  }
]

Current Output :

{
  "tab": {
    "text": "123456789"
  },
  "address": [
    {
      "add": "UK",
      "add2": "US",
      "mk": "mk"
    }
  ],
  "Photos": [
    {
      "caption2": "http.1.com",
      "no": 222444
    },
    {
      "caption2": "http.2.com",
      "no": 222444
    },
    {
      "caption2": "TEST>> photo 1",
      "no": 327703
    },
    {
      "caption2": "TEST>> photo 2",
      "no": 327704
    },
    {
      "caption2": "TEST>> photo 2",
      "no": 327704
    }
  ]
}

Expected Output ( i need "no" in string like below ) :

{
  "tab": {
    "text": "123456789"
  },
  "address": [
    {
      "add": "UK",
      "add2": "US",
      "mk": "mk"
    }
  ],
  "Photos": [
    {
      "caption2": "http.1.com",
      "no": "222444"
    },
    {
      "caption2": "http.2.com",
      "no": "222444"
    },
    {
      "caption2": "TEST>> photo 1",
      "no": "327703"
    },
    {
      "caption2": "TEST>> photo 2",
      "no": "327704"
    },
    {
      "caption2": "TEST>> photo 2",
      "no": "327704"
    }
  ]
}

CodePudding user response:

You can add a modify transformation to the current spec along with toString function such as

 ,
{
  "operation": "modify-overwrite-beta",
  "spec": {
    "Photos": {
      "*": {
        "no": "=toString"
      }
    }
  }
}
  • Related