Home » Javascript » Parse json object with back slashes and add it back into the data json

Parse json object with back slashes and add it back into the data json

Posted by: admin August 19, 2018 Leave a comment

Questions:

Just wondering, in the JSON below, is it possible to parse through the single object call ‘Data’, remove the back slashes, separate each key value pairs in the single object, and then append it back into the original JSON data.

This:

{
  "Timestamp": "2018-05-14T20:02:57.000Z",
  "Data": "{\"UserId\":\"00529000001jD4uAAE\",\"CardElement\":\"Total Due\",\"EntityLabel\":\"Total Due\",\"EntityName\":\"Contract Account\",\"TrackingEvent\":\"Field\",\"TrackingService\":\"VCards\"}",
  "CustomerInteractionId": "a1629000000VQgvAAG",
  "Vlocity Tracking Entry Name": "Field"
}

Turns into this:

 {
  "Timestamp": "2018-05-14T20:02:57.124Z",
  "CustomerInteractionId": "a1629000000VQgvAAG",
  "Vlocity Tracking Entry Name": "Field",
  "UserId": "00529000001jD4uAAE",
  "CardElement": "Total Due",
  "EntityLabel": "Contract Account",
  "TrackingEvent": "Field",
  "TrackingService": "VCards"
}

Having some issues breaking it down to their own key value pairs and appending it back into the JSON. Can be in JS or AngularJS

Answers: