0

I have a couple cases where I need to transform map fields into array fields that are sometimes nested a couple layers deep. These are the only fields that need to change in the document, so the other fields don't need any sort of transformation performed on them. My current approach is to copy over the unchanged fields at each level, like this:

[
  {
    "operation": "shift",
    "spec": {
      "agentsMetrics": {
        "metricsPerAgent": {
          "*": {
            "$": "agentsMetrics.metricsPerAgent[#2].agentId",
            "@": "agentsMetrics.metricsPerAgent[#2].value"
          }
        },
        "*": {
          "@": "agentsMetrics.&"
        }
      },
      "skillsMetricsPerAgent": {
        "metricsPerSkill": {
          "*": {
            "$": "skillsMetricsPerAgent.metricsPerSkill[#2].skillId",
            "metricsPerAgent": {
              "*": {
                "$": "skillsMetricsPerAgent.metricsPerSkill[#4].metricsPerAgent[#2].agentId",
                "@": "skillsMetricsPerAgent.metricsPerSkill[#4].metricsPerAgent[#2].value"
              }
            },
            "*": {
              "@": "skillsMetricsPerAgent.metricsPerSkill[#3].&"
            }
          }
        },
        "*": {
          "@": "skillsMetricsPerAgent.&"
        }
      }
    }
  }
]

Where my input looks like this:

{
    "agentsMetrics": {
        "metricsTotals": {
            "connectedEngagements": 70,
            "nonInteractiveTotalHandlingTime": 309,
            "totalHandlingTime": 47696,
            "totalNonInteractiveChats": 2,
            "totalInteractiveChats": 73
        },
        "metricsPerAgent": {
            "645355412": {
                "connectedEngagements": 2,
                "nonInteractiveTotalHandlingTime": 0,
                "totalHandlingTime": 1718,
                "totalNonInteractiveChats": 0,
                "totalInteractiveChats": 2
            },
            "645366912": {
                "connectedEngagements": 1,
                "nonInteractiveTotalHandlingTime": 0,
                "totalHandlingTime": 488,
                "totalNonInteractiveChats": 0,
                "totalInteractiveChats": 1
            }
        }
    },
    "skillsMetricsPerAgent": {
        "metricsTotals": {
            "connectedEngagements": 70,
            "nonInteractiveTotalHandlingTime": 309,
            "totalHandlingTime": 47696,
            "totalNonInteractiveChats": 2,
            "totalInteractiveChats": 73
        },
        "metricsPerSkill": {
            "641431612": {
                "metricsTotals": {
                    "connectedEngagements": 7,
                    "nonInteractiveTotalHandlingTime": 0,
                    "totalHandlingTime": 6377,
                    "totalNonInteractiveChats": 0,
                    "totalInteractiveChats": 8
                },
                "metricsPerAgent": {
                    "645355312": {
                        "connectedEngagements": 1,
                        "nonInteractiveTotalHandlingTime": 0,
                        "totalHandlingTime": 115,
                        "totalNonInteractiveChats": 0,
                        "totalInteractiveChats": 1
                    },
                    "645365512": {
                        "connectedEngagements": 0,
                        "nonInteractiveTotalHandlingTime": 0,
                        "totalHandlingTime": 766,
                        "totalNonInteractiveChats": 0,
                        "totalInteractiveChats": 1
                    }
                }
            },
            "1218517512": {
                "metricsTotals": {
                    "connectedEngagements": 2,
                    "nonInteractiveTotalHandlingTime": 0,
                    "totalHandlingTime": 1379,
                    "totalNonInteractiveChats": 0,
                    "totalInteractiveChats": 2
                },
                "metricsPerAgent": {
                    "645367512": {
                        "connectedEngagements": 1,
                        "nonInteractiveTotalHandlingTime": 0,
                        "totalHandlingTime": 571,
                        "totalNonInteractiveChats": 0,
                        "totalInteractiveChats": 1
                    },
                    "645378812": {
                        "connectedEngagements": 1,
                        "nonInteractiveTotalHandlingTime": 0,
                        "totalHandlingTime": 808,
                        "totalNonInteractiveChats": 0,
                        "totalInteractiveChats": 1
                    }
                }
            }
        }
    }
}

Is there any way to target specific fields and manipulate them on their own while leaving everything else as it is? In this case I'd like to target metricsPerAgent and metricsPerSkill.

ggeise
  • 467
  • 1
  • 5
  • 9

2 Answers2

1

Is there any way to target specific fields and manipulate them on their own while leaving everything else as it is?

No / not with shift / not currently. Note the "shift" operation is making a copy, from the input to the output.

Milo S
  • 4,466
  • 1
  • 19
  • 22
0

This approach seems to work (haven't tested thoroughly or evaluated the efficiency, though):

{
    "operation": "shift",
    "spec": {
        // derived from https://stackoverflow.com/questions/40494231/re-parent-a-json-object-using-jolt#40513842
        "*": {
            "@": "&"
        },
        // any specific shifts go here
    }
}
Janaka Bandara
  • 1,024
  • 1
  • 12
  • 27