0

I have a below output from the server.And I want to get the "result" from the JSON input.

My JSON Input is

{      
"header":{  
"type":"esummary",
"version":"0.3"
},
"result":{  
    "28885854":{  
    "uid":"28885854",
    "pubdate":"2017 Sep 8",
    "epubdate":"2017 Sep 8",
    "source":"J Org Chem",
    }
  }
} 

And I prefer only javascript.Anyone help me to do this.

EDIT :

I tried the code to get JSON from server

var json = JSON.stringify(temp1);
console.log(json)

My original output in the console was like this.

" {"header":{"type":"esummary","version":"0.3"},"result":{"28885854":{"uid":"28885854","pubdate":"2017 Sep 8","epubdate":"2017 Sep 8","source":"J Org Chem","authors":[{"name":"Farmer LA","authtype":"Author","clusterid":""},{"name":"Haidasz EA","authtype":"Author","clusterid":""},{"name":"Griesser M","authtype":"Author","clusterid":""},{"name":"Pratt DA","authtype":"Author","clusterid":""}],"lastauthor":"Pratt DA","title":"Phenoxazine: A Privileged Scaffold for Radical-Trapping Antioxidants.","sorttitle":"phenoxazine a privileged scaffold for radical trapping antioxidants","volume":"","issue":"","pages":"","lang":["eng"],"nlmuniqueid":"2985193R","issn":"0022-3263","essn":"1520-6904","pubtype":["Journal Article"],"recordstatus":"PubMed - as supplied by publisher","pubstatus":"10","articleids":[{"idtype":"pubmed","idtypen":1,"value":"28885854"},{"idtype":"doi","idtypen":3,"value":"10.1021/acs.joc.7b02025"},{"idtype":"rid","idtypen":8,"value":"28885854"},{"idtype":"eid","idtypen":8,"value":"28885854"}],"history":[{"pubstatus":"entrez","date":"2017/09/09 06:00"},{"pubstatus":"pubmed","date":"2017/09/09 06:00"},{"pubstatus":"medline","date":"2017/09/09 06:00"}],"references":[],"attributes":["Has Abstract"],"pmcrefcount":"","fulljournalname":"The Journal of organic chemistry","elocationid":"doi: 10.1021/acs.joc.7b02025","doctype":"citation","srccontriblist":[],"booktitle":"","medium":"","edition":"","publisherlocation":"","publishername":"","srcdate":"","reportnumber":"","availablefromurl":"","locationlabel":"","doccontriblist":[],"docdate":"","bookname":"","chapter":"","sortpubdate":"2017/09/08 00:00","sortfirstauthor":"Farmer LA","vernaculartitle":""},"uids":["28885854"]}} "

Object What i Get

1 Answer 1

5

I think all you're looking for is .result. Perhaps you also want JSON.parse(...) if you have just the JSON string so far.

var obj = {
  "header": {
    "type": "esummary",
    "version": "0.3"
  },
  "result": {
    "28885854": {
      "uid": "28885854",
      "pubdate": "2017 Sep 8",
      "epubdate": "2017 Sep 8",
      "source": "J Org Chem",
    }
  }
};

console.log(obj.result);

// To address edits above and comments below:
console.log(obj.result["28885854"].source);

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

10 Comments

When i'm using console.log(json.result) it will give undefined
Why are you calling JSON.stringify?
Per your edit, don't you just want console.log(temp1.result)?
temp1 is not a JSON
So,that I'm using the way I said
|

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.