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
  }
]

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Added Object.assign to prevent mutation of original data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.