Skip to content

JSON Transform Only Returning 1st Item in JSON Object #87

Description

@ruskspace

I am using object-mapper to transform a JSON object to a different JSON format. The following works... but only produces the first entry in the JSON I have. Is there some sort of foreach or iteration that needs to be added?

This:

  var src = response.data;

  var map = {
    "value.segments.start": "value.start",
    "value.segments.end": "value.end",
    "value.segments.segments.performanceCounters/processCpuPercentage.avg": "value.cpu"
  };

  var dest = objectMapper(src, map);

  res.send(dest);

Produces this:

{
  "value": {
    "start": "2021-04-15T00:00:00.000Z",
    "end": "2021-04-16T00:00:00.000Z",
    "cpu": 9.01
  }
}

But here is my response.data as I get JSON from one source and need to transform it to another format, as you can see multiple entries and I expected to multiple entries in the object-mapped output:

{
  "value": {
    "start": "2021-04-14T18:17:27.086Z",
    "end": "2021-04-15T18:17:27.086Z",
    "interval": "PT1H",
    "segments": [
      {
        "start": "2021-04-14T18:17:27.086Z",
        "end": "2021-04-14T19:00:00.000Z",
        "segments": [
          {
            "performanceCounters/processCpuPercentage": {
              "avg": 22.9
            },
            "customDimensions/Role": "CD"
          }
        ]
      },
      {
        "start": "2021-04-14T19:00:00.000Z",
        "end": "2021-04-14T20:00:00.000Z",
        "segments": [
          {
            "performanceCounters/processCpuPercentage": {
              "avg": 23.51
            },
            "customDimensions/Role": "CD"
          }
        ]
      },
      {
        "start": "2021-04-15T00:00:00.000Z",
        "end": "2021-04-15T01:00:00.000Z",
        "segments": [
          {
            "performanceCounters/processCpuPercentage": {
              "avg": 8.85
            },
            "customDimensions/Role": "CD"
          }
        ]
      },

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions