Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ruskspace opened this issue Apr 21, 2021 · 0 comments
Open

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

ruskspace opened this issue Apr 21, 2021 · 0 comments

Comments

@ruskspace
Copy link

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"
          }
        ]
      },
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant