Kyler Phillips Kyler Phillips - 5 months ago 7
JSON Question

Remove {"Result": in JSON string

I have the following JSON result when calling an API, how can I convert the JSON string I have so I can just see the results:

var response = request_.responseText;
var obj = JSON.parse(request_.response);

var j = obj;
var js = JSON.stringify(j)
console.log(js)


JSON Output of
var js
:

{"Result":[{"PK_ID":1,"MedicationId":1,"NHS_Number":"123","Medication_Name":"Asprin","Read_Code":"XaaYI","Dose":"500mg","Date_Started":"02/06/2016","Date_Ended":"03/06/2016"},{"PK_ID":2,"MedicationId":2,"NHS_Number":"1234","Medication_Name":"Ibuprofen","Read_Code":"EtQWEl","Dose":"100mg","Date_Started":"03/02/2016","Date_Ended":"05/02/2016"}]}


How can I remove the
{"Result": }
code that is wrapped around my JSON?

Answer

Update from

 var j = obj;

to

 var j = obj.Result;

var obj = {
  "Result": [{
    "PK_ID": 1,
    "MedicationId": 1,
    "NHS_Number": "123",
    "Medication_Name": "Asprin",
    "Read_Code": "XaaYI",
    "Dose": "500mg",
    "Date_Started": "02/06/2016",
    "Date_Ended": "03/06/2016"
  }, {
    "PK_ID": 2,
    "MedicationId": 2,
    "NHS_Number": "1234",
    "Medication_Name": "Ibuprofen",
    "Read_Code": "EtQWEl",
    "Dose": "100mg",
    "Date_Started": "03/02/2016",
    "Date_Ended": "05/02/2016"
  }]
};

var j = obj.Result;
var js = JSON.stringify(j);

console.log(js);

Comments