Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Duplicate answers where was to be one #78

Open
jobdiogenes opened this issue Feb 9, 2023 · 1 comment
Open

Duplicate answers where was to be one #78

jobdiogenes opened this issue Feb 9, 2023 · 1 comment

Comments

@jobdiogenes
Copy link

I'm get this package to use with ORCID api, but I got duplicate answers where I need just one.

to replicate do this using nodejs:

const fetch = require('node-fetch');
const JSPath = require('jspath');

let doi = '0000-0002-2109-9738';
const api =  "https://pub.orcid.org/v3.0";

const options =  {
   'method' : 'get',
   'muteHttpExceptions' : true,
   'headers' : {
     'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36',
     'Accept': 'application/json'
   };

// call api
let works = await fetch(api+'/'+Orcid+'/works',options).then(resp=>resp.json());

// get content direct 
works.group[0]['external-ids']
// output this:
/* 
{
 'external-id': [
   {
     'external-id-type': 'doi',
     'external-id-value': '10.1007/s10530-022-02974-5',
     'external-id-normalized': [Object],
     'external-id-normalized-error': null,
     'external-id-url': [Object],
     'external-id-relationship': 'self'
   }
 ]
}
*/

JSPath.apply('.."external-id"', works.group[0])
// output this:
/* 
[
 {
   'external-id-type': 'doi',
   'external-id-value': '10.1007/s10530-022-02974-5',
   'external-id-normalized': { value: '10.1007/s10530-022-02974-5', transient: true },
   'external-id-normalized-error': null,
   'external-id-url': { value: 'https://doi.org/10.1007/s10530-022-02974-5' },
   'external-id-relationship': 'self'
 },
 {
   'external-id-type': 'doi',
   'external-id-value': '10.1007/s10530-022-02974-5',
   'external-id-normalized': { value: '10.1007/s10530-022-02974-5', transient: true },
   'external-id-normalized-error': null,
   'external-id-url': { value: 'https://doi.org/10.1007/s10530-022-02974-5' },
   'external-id-relationship': 'self'
 }
]
*/
@dfilatov
Copy link
Owner

dfilatov commented Feb 16, 2023

Hi!

I've tried this:

const doc = {
    'external-ids': {
        'external-id': [
            {
                'external-id-type': 'doi',
                'external-id-value': '10.1007/s10530-022-02974-5',
                'external-id-normalized': [],
                'external-id-normalized-error': null,
                'external-id-url': [],
                'external-id-relationship': 'self'
            }
        ]
    }
};

console.log(JSPath.apply('.."external-id"', doc));

Output is:

[
  {
    'external-id-type': 'doi',
    'external-id-value': '10.1007/s10530-022-02974-5',
    'external-id-normalized': [],
    'external-id-normalized-error': null,
    'external-id-url': [],
    'external-id-relationship': 'self'
  }
]

Give me more details, I don't know what works.group[0] structure is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants