0

Currently I am having very large JSON data and I want to make trimmed version before I use the JSON data to process in Angular JS Controller.

In the Below JSON Data ,I dont want to have comment and htmlComment element , How I can delete those and have new very light version JSON data before I process the data

Here To make simplicity I have made very easy JSON Array, But in real I have very data which is almost 100mb.

I have gone thorugh many questions still not able to make

  1. Ref 1
  2. Ref 2
  3. Ref 3

Below is the JSON Data

[
  {
    "executions": [
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      }
    ],
    "currentlySelectedExecutionId": "",
    "recordsCount": 210,
    "stepDefectCount": 0,
    "totalDefectCount": 0
  },
  {
    "executions": [
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      }
    ],
    "currentlySelectedExecutionId": "",
    "recordsCount": 210,
    "stepDefectCount": 0,
    "totalDefectCount": 0
  },
  {
    "executions": [
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      },
      {
        "id": 241049,
        "orderId": 212250,
        "executionStatus": "1",
        "executedOn": "19/Jul/17 7:42 PM",
        "executedBy": "ext1",
        "executedByDisplay": "Person1",
        "comment": "Comment1",
        "htmlComment": "HTML1"
      }
    ],
    "currentlySelectedExecutionId": "",
    "recordsCount": 210,
    "stepDefectCount": 0,
    "totalDefectCount": 0
  }
]
Mahesh G
  • 1,226
  • 4
  • 30
  • 57

1 Answers1

1

Use a map on each of your arrays of data:

var lightData = rawData.map(function(item) { 
  // use Object.assign to prevent mutating original object
  var newItem = Object.assign({}, item);
  var lightExecutions = item.executions.map(function(d) {
    var ld = {
      id: d.id,
      orderId: d.orderId,
      executionStatus: d.executionStatus,
      executedOn: d.executedOn,
      executedBy: d.executedBy,
      executedByDisplay: d.executedByDisplay,
    };
    return ld;
  });
  newItem.executions = lightExecutions;
  return newItem;
});

Only the fields you include in the mapped object will populate the new dataset.

Pop-A-Stash
  • 6,572
  • 5
  • 28
  • 54